update qrmaster and itemmovement table
This commit is contained in:
parent
ea4666690e
commit
79fb9649d7
@ -342,6 +342,31 @@
|
|||||||
{
|
{
|
||||||
"title": "Note",
|
"title": "Note",
|
||||||
"data": "item.consignmentNote",
|
"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",
|
"title": "Send Date",
|
||||||
|
|||||||
@ -201,8 +201,6 @@
|
|||||||
|
|
||||||
this.fetchRequest();
|
this.fetchRequest();
|
||||||
|
|
||||||
// Reset the form
|
|
||||||
this.resetForm();
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to submit form.');
|
throw new Error('Failed to submit form.');
|
||||||
}
|
}
|
||||||
@ -625,31 +623,6 @@
|
|||||||
// Your currency conversion logic here
|
// Your currency conversion logic here
|
||||||
console.log('Selected currency:', this.currency);
|
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
|
// FRONT END FUNCTIONS
|
||||||
//----------------------//
|
//----------------------//
|
||||||
|
|||||||
@ -351,19 +351,19 @@
|
|||||||
selectedOther: "",
|
selectedOther: "",
|
||||||
remark: "",
|
remark: "",
|
||||||
document: null,
|
document: null,
|
||||||
companies: [
|
// companies: [
|
||||||
{
|
// {
|
||||||
companyId: 1,
|
// companyId: 1,
|
||||||
companyName: "PSTW",
|
// companyName: "PSTW",
|
||||||
departments: [{ departmentId: 1, departmentName: "Air" }, { departmentId: 2, departmentName: "Marine" }, { departmentId: 3, departmentName: "River" }]
|
// departments: [{ departmentId: 1, departmentName: "Air" }, { departmentId: 2, departmentName: "Marine" }, { departmentId: 3, departmentName: "River" }]
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
companyId: 2,
|
// companyId: 2,
|
||||||
companyName: "TES",
|
// companyName: "TES",
|
||||||
departments: [{ departmentId: 1, departmentName: "Air" }],
|
// departments: [{ departmentId: 1, departmentName: "Air" }],
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
company: "",
|
// company: "",
|
||||||
currentUser: null,
|
currentUser: null,
|
||||||
currentUserCompanyDept: null,
|
currentUserCompanyDept: null,
|
||||||
}
|
}
|
||||||
@ -419,37 +419,20 @@
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const formData = {
|
const formData = {
|
||||||
|
|
||||||
...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, } : {}),
|
...(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} : {}),
|
...(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, } : {}),
|
...(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 } : {}),
|
...(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,
|
ItemId: this.thisItem.itemID,
|
||||||
Action: 'Stock Out',
|
Action: 'Stock Out',
|
||||||
Quantity: 1,
|
Quantity: 1,
|
||||||
MovementComplete: false,
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
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
|
// Proceed to send the data to the API
|
||||||
const response = await fetch('/InvMainAPI/AddItemMovement', {
|
const response = await fetch('/InvMainAPI/AddItemMovement', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -462,8 +445,9 @@
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
// If the form submission was successful, display a success message
|
// If the form submission was successful, display a success message
|
||||||
alert('Success!', 'Item form has been successfully submitted.', 'success');
|
alert('Success!', 'Item form has been successfully submitted.', 'success');
|
||||||
const updatedItem = await response.json();
|
// const updatedItem = await response.json();
|
||||||
// this.items.push(updatedItem);
|
// this.items.push(updatedItem);
|
||||||
|
// console.log(updatedItem);
|
||||||
|
|
||||||
// Reset the form
|
// Reset the form
|
||||||
this.resetForm();
|
this.resetForm();
|
||||||
@ -552,6 +536,7 @@
|
|||||||
resetForm() {
|
resetForm() {
|
||||||
this.selectedUser = "";
|
this.selectedUser = "";
|
||||||
this.selectedStore = "";
|
this.selectedStore = "";
|
||||||
|
this.selectedSupplier = "";
|
||||||
this.remark = "";
|
this.remark = "";
|
||||||
this.assigndate = "";
|
this.assigndate = "";
|
||||||
this.selectedStore = "";
|
this.selectedStore = "";
|
||||||
@ -585,28 +570,6 @@
|
|||||||
console.error('There was a problem with the fetch operation:', error);
|
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() {
|
async fetchUsers() {
|
||||||
try {
|
try {
|
||||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
// 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)
|
public async Task<IActionResult> AddItemMovement([FromBody] ItemMovementModel itemmovement)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
@ -672,6 +670,18 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
|
|
||||||
try
|
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))
|
if (!string.IsNullOrEmpty(itemmovement.ConsignmentNote))
|
||||||
{
|
{
|
||||||
@ -702,70 +712,33 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
|
|
||||||
await _centralDbContext.SaveChangesAsync(); // This generates the auto-incremented ItemID
|
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
|
if (updateItem != null)
|
||||||
//{
|
{
|
||||||
// ItemId = item.ItemID,
|
if (itemmovement.ToOther == "On Delivery")
|
||||||
// ToUser = inventoryMaster.UserId,
|
{
|
||||||
// ToStore = inventoryMaster.StoreId,
|
updateItem.ItemStatus = 2;
|
||||||
// LastStore = inventoryMaster.StoreId,
|
}
|
||||||
// LastUser = inventoryMaster.UserId,
|
else if (itemmovement.ToOther == "Repair" || itemmovement.ToOther == "Calibration")
|
||||||
// LatestStatus = "Ready To Deploy",
|
{
|
||||||
// Quantity = item.Quantity,
|
updateItem.ItemStatus = 4;
|
||||||
// Action = "Register",
|
}
|
||||||
// Date = DateTime.Now,
|
else if (itemmovement.ToOther == "Faulty")
|
||||||
// MovementComplete = true,
|
{
|
||||||
//};
|
updateItem.ItemStatus = 8;
|
||||||
|
}
|
||||||
|
|
||||||
//_centralDbContext.ItemMovements.Add(itemMovement);
|
Console.WriteLine("updateItem.MovementId" + updateItem.MovementId);
|
||||||
//await _centralDbContext.SaveChangesAsync();
|
Console.WriteLine("itemmovement.Id" + itemmovement.Id);
|
||||||
|
|
||||||
// Fetch the generated ItemID
|
updateItem.MovementId = itemmovement.Id;
|
||||||
//var savedItem = await _centralDbContext.Items.FirstOrDefaultAsync(i => i.ItemID == item.ItemID);
|
_centralDbContext.Items.Update(updateItem);
|
||||||
//// Fetch the generated itemMovement
|
|
||||||
//var savedMovement = await _centralDbContext.ItemMovements.FirstOrDefaultAsync(i => i.Id == itemMovement.Id);
|
|
||||||
|
|
||||||
//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();
|
await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid
|
||||||
// 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;
|
|
||||||
|
|
||||||
// _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);
|
return Json(itemmovement);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue
Block a user