update qrmaster and itemmovement table
This commit is contained in:
parent
ea4666690e
commit
79fb9649d7
@ -342,6 +342,31 @@
|
||||
{
|
||||
"title": "Note",
|
||||
"data": "item.consignmentNote",
|
||||
"render": function (data, type, full, meta) {
|
||||
if (!data) {
|
||||
return "No Document";
|
||||
}
|
||||
|
||||
// Check if the document is an image based on file extension
|
||||
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
|
||||
var isPdf = /\.pdf$/i.test(data);
|
||||
|
||||
if (isImage) {
|
||||
return `<a href="${data}" target="_blank" data-lightbox="image-1">
|
||||
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
|
||||
</a>`;
|
||||
} else if (isPdf) {
|
||||
return `<a href="${data}" target="_blank">
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
|
||||
alt="PDF Document" class="img-thumbnail"
|
||||
style="width: 50px; height: 50px;" />
|
||||
<br>View PDF
|
||||
</a>`;
|
||||
} else {
|
||||
return `<a href="${data}" target="_blank">Download File</a>`;
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
"title": "Send Date",
|
||||
|
||||
@ -201,8 +201,6 @@
|
||||
|
||||
this.fetchRequest();
|
||||
|
||||
// Reset the form
|
||||
this.resetForm();
|
||||
} else {
|
||||
throw new Error('Failed to submit form.');
|
||||
}
|
||||
@ -625,31 +623,6 @@
|
||||
// Your currency conversion logic here
|
||||
console.log('Selected currency:', this.currency);
|
||||
},
|
||||
resetForm() {
|
||||
// this.company = '';
|
||||
// this.Dept = null;
|
||||
// this.productName = null;
|
||||
// this.imageProduct = null;
|
||||
// this.serialNumber = '';
|
||||
// this.quantity = 1;
|
||||
// this.supplierName = null;
|
||||
// this.purchaseDate = null;
|
||||
// this.PO = null;
|
||||
// this.currency = 'MYR';
|
||||
// this.DefaultPrice = 0.01;
|
||||
// this.currencyRate = 1;
|
||||
// this.convertPrice = 0.01;
|
||||
// this.DODate = null;
|
||||
// this.warranty = 0;
|
||||
// this.EndWDate = null;
|
||||
// this.invoiceDate = null;
|
||||
// this.selectedProduct = '';
|
||||
// this.selectedSupplier = '';
|
||||
// this.selectedCompany = this.currentUserCompanyDept.companyId;
|
||||
// this.selectedDepartment = '';
|
||||
// this.selectedTeamType = '';
|
||||
// this.partNumber = null;
|
||||
},
|
||||
|
||||
// FRONT END FUNCTIONS
|
||||
//----------------------//
|
||||
|
||||
@ -351,19 +351,19 @@
|
||||
selectedOther: "",
|
||||
remark: "",
|
||||
document: null,
|
||||
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: "",
|
||||
// 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: "",
|
||||
currentUser: null,
|
||||
currentUserCompanyDept: null,
|
||||
}
|
||||
@ -419,37 +419,20 @@
|
||||
const now = new Date();
|
||||
const formData = {
|
||||
|
||||
...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, } : {}),
|
||||
...(this.selectedAction === 'store' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedStore} : {}),
|
||||
...(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, } : {}),
|
||||
...(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 } : {}),
|
||||
...(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 === '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 === '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,
|
||||
MovementComplete: false,
|
||||
|
||||
|
||||
};
|
||||
|
||||
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/AddItemMovement', {
|
||||
method: 'POST',
|
||||
@ -462,8 +445,9 @@
|
||||
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();
|
||||
// const updatedItem = await response.json();
|
||||
// this.items.push(updatedItem);
|
||||
// console.log(updatedItem);
|
||||
|
||||
// Reset the form
|
||||
this.resetForm();
|
||||
@ -552,6 +536,7 @@
|
||||
resetForm() {
|
||||
this.selectedUser = "";
|
||||
this.selectedStore = "";
|
||||
this.selectedSupplier = "";
|
||||
this.remark = "";
|
||||
this.assigndate = "";
|
||||
this.selectedStore = "";
|
||||
@ -585,28 +570,6 @@
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
},
|
||||
async fetchStoreId() {
|
||||
try {
|
||||
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
this.currentUser = data?.userInfo || null;
|
||||
const companyDeptData = await this.currentUser.department;
|
||||
this.currentUserCompanyDept = companyDeptData;
|
||||
this.selectedCompany = companyDeptData?.companyId || "";
|
||||
this.selectedDepartment = companyDeptData?.departmentId || "";
|
||||
|
||||
}
|
||||
else {
|
||||
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
},
|
||||
async fetchUsers() {
|
||||
try {
|
||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
||||
|
||||
@ -663,8 +663,6 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
||||
public async Task<IActionResult> AddItemMovement([FromBody] ItemMovementModel itemmovement)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
@ -672,6 +670,18 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
||||
|
||||
try
|
||||
{
|
||||
if (itemmovement.ToUser == 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.FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser);
|
||||
if (inventoryMaster != null)
|
||||
{
|
||||
itemmovement.ToStore = inventoryMaster.StoreId;
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(itemmovement.ConsignmentNote))
|
||||
{
|
||||
@ -702,70 +712,33 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
||||
|
||||
await _centralDbContext.SaveChangesAsync(); // This generates the auto-incremented ItemID
|
||||
|
||||
var updateItem = await _centralDbContext.Items.FindAsync(itemmovement.ItemId); //only access after it have its own itemmovent
|
||||
|
||||
//ItemMovementModel itemMovement = new ItemMovementModel
|
||||
//{
|
||||
// ItemId = item.ItemID,
|
||||
// ToUser = inventoryMaster.UserId,
|
||||
// ToStore = inventoryMaster.StoreId,
|
||||
// LastStore = inventoryMaster.StoreId,
|
||||
// LastUser = inventoryMaster.UserId,
|
||||
// LatestStatus = "Ready To Deploy",
|
||||
// Quantity = item.Quantity,
|
||||
// Action = "Register",
|
||||
// Date = DateTime.Now,
|
||||
// MovementComplete = true,
|
||||
//};
|
||||
if (updateItem != null)
|
||||
{
|
||||
if (itemmovement.ToOther == "On Delivery")
|
||||
{
|
||||
updateItem.ItemStatus = 2;
|
||||
}
|
||||
else if (itemmovement.ToOther == "Repair" || itemmovement.ToOther == "Calibration")
|
||||
{
|
||||
updateItem.ItemStatus = 4;
|
||||
}
|
||||
else if (itemmovement.ToOther == "Faulty")
|
||||
{
|
||||
updateItem.ItemStatus = 8;
|
||||
}
|
||||
|
||||
//_centralDbContext.ItemMovements.Add(itemMovement);
|
||||
//await _centralDbContext.SaveChangesAsync();
|
||||
Console.WriteLine("updateItem.MovementId" + updateItem.MovementId);
|
||||
Console.WriteLine("itemmovement.Id" + itemmovement.Id);
|
||||
|
||||
// Fetch the generated ItemID
|
||||
//var savedItem = await _centralDbContext.Items.FirstOrDefaultAsync(i => i.ItemID == item.ItemID);
|
||||
//// Fetch the generated itemMovement
|
||||
//var savedMovement = await _centralDbContext.ItemMovements.FirstOrDefaultAsync(i => i.Id == itemMovement.Id);
|
||||
updateItem.MovementId = itemmovement.Id;
|
||||
_centralDbContext.Items.Update(updateItem);
|
||||
|
||||
//if (savedItem != null)
|
||||
//{
|
||||
// var companyDepartment = await GetDepartmentWithCompany(item.CompanyId, item.DepartmentId);
|
||||
// var itemProduct = _centralDbContext.Products.Where(p => p.ProductId == item.ProductId).FirstOrDefault();
|
||||
}
|
||||
|
||||
// string? companyInitial = companyDepartment!.CompanyName?.ToString().Substring(0, 1).ToUpper();
|
||||
// string? departmentInitial = companyDepartment!.DepartmentName?.ToString().Substring(0, 1).ToUpper();
|
||||
// string? deptCode = companyDepartment!.DepartmentCode?.ToString();
|
||||
// char? initialCategory = itemProduct!.Category.ToString().Substring(0, 1).ToUpper().FirstOrDefault();
|
||||
// string? productId = itemProduct!.ProductId.ToString("D3");
|
||||
// string? itemId = item.ItemID.ToString("D5");
|
||||
// var uniqueId = $"{deptCode}{initialCategory}{productId}{itemId}".ToUpper();
|
||||
// savedItem.UniqueID = uniqueId;
|
||||
// savedItem.MovementId = savedMovement?.Id;
|
||||
await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid
|
||||
|
||||
// _centralDbContext.Items.Update(savedItem);
|
||||
// await _centralDbContext.SaveChangesAsync();
|
||||
//}
|
||||
|
||||
//var updatedItem = new
|
||||
//{
|
||||
// savedItem!.ItemID,
|
||||
// savedItem.UniqueID,
|
||||
// savedItem.CompanyId,
|
||||
// savedItem.DepartmentId,
|
||||
// savedItem.ProductId,
|
||||
// savedItem.SerialNumber,
|
||||
// savedItem.Quantity,
|
||||
// savedItem.Supplier,
|
||||
// savedItem.PurchaseDate,
|
||||
// savedItem.PONo,
|
||||
// savedItem.Currency,
|
||||
// savedItem.DefaultPrice,
|
||||
// savedItem.CurrencyRate,
|
||||
// savedItem.ConvertPrice,
|
||||
// savedItem.DODate,
|
||||
// savedItem.Warranty,
|
||||
// savedItem.EndWDate,
|
||||
// savedItem.InvoiceDate,
|
||||
// savedItem.PartNumber,
|
||||
//};
|
||||
return Json(itemmovement);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue
Block a user