public async Task<PagedList<QRCodeMainViewModel>> SearchByPlanNo(PaginationParams param ,FilterQrCodeParam filterParam) { var listPackingList = _repoPacking.GetAll(); if (filterParam.From_Date != null && filterParam.To_Date != null) { listPackingList = listPackingList .Where( x => x.Receive_Date >= Convert.ToDateTime(filterParam.From_Date + " 00:00:00.000") && x.Receive_Date <= Convert.ToDateTime(filterParam.To_Date + " 23:59:59.997")); } var listQrCodeMain = _repoQrcode.GetAll().Where(x => x.Is_Scanned.Trim() == "N"); if (filterParam.MO_No != null && filterParam.MO_No != string.Empty) { listPackingList = listPackingList.Where(x => x.MO_No.Trim() == filterParam.MO_No.Trim()); } var listQrCodeModel = (from x in listQrCodeMain join y in listPackingList on x.Receive_No.Trim() equals y.Receive_No.Trim() select new QRCodeMainViewModel() { QRCode_ID = x.QRCode_ID, MO_No = y.MO_No, QRCode_Version = x.QRCode_Version, Receive_No = x.Receive_No, Receive_Date = y.Receive_Date, Supplier_ID = y.Supplier_ID, Supplier_Name = y.Supplier_Name, T3_Supplier = y.T3_Supplier, T3_Supplier_Name = y.T3_Supplier_Name, Subcon_ID = y.Subcon_ID, Subcon_Name = y.Subcon_Name, Model_Name = y.Model_Name, Model_No = y.Model_No, Article = y.Article, MO_Seq = y.MO_Seq, Material_ID = y.Material_ID, Material_Name = y.Material_Name }).Distinct().OrderByDescending(x => x.Receive_Date); return await PagedList<QRCodeMainViewModel>.CreateAsync(listQrCodeModel, param.PageNumber, param.PageSize); }
// ---Phần in QrCodeId khi vào Menu 2.QrGenerate => Print (Material Form)-------// public async Task <object> FindByQrCodeID(QrCodeIDVersion data) { var qrCodeMan = await _repoQrcode.GetAll() .Where(x => x.QRCode_ID.Trim() == data.QRCode_ID.Trim() && x.QRCode_Version == data.QRCode_Version).FirstOrDefaultAsync(); var packingList = await _repoPackingList.GetAll().ToListAsync(); // Tìm kiếm Purchase và Sheet_Type của qrcodeid với version đó. var packingListFind = packingList .Where(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).FirstOrDefault(); // Tìm List ReceiveNo tương ứng với Purchase và Sheet_Type ở trên var ReceiveNoList = packingList .Where(x => x.Sheet_Type.Trim() == packingListFind.Sheet_Type.Trim() && x.Purchase_No.Trim() == packingListFind.Purchase_No.Trim() && x.Receive_Date <= packingListFind.Receive_Date) .Select(x => x.Receive_No).ToList(); var packingListDetailAll = await _repoPackingListDetail.GetAll().ToListAsync(); var packingDetailList = new List <WMSB_PackingList_Detail>(); foreach (var item in ReceiveNoList) { var packingdetailitem = packingListDetailAll.Where(x => x.Receive_No.Trim() == item.Trim()).ToList(); packingDetailList.AddRange(packingdetailitem); } // Gộp theo từng tool size và tính tổng Purchase, Received Qty theo tool size đó. var BalByToolSize = packingDetailList.GroupBy(x => x.Tool_Size).Select(x => new { Tool_Size = x.FirstOrDefault().Tool_Size, Bal = x.Sum(cl => cl.Purchase_Qty) / (ReceiveNoList.Count()) - x.Sum(cl => cl.Received_Qty) }); var packingListDetailModel = new List <PackingListDetailViewModel>(); var packingListDetailModel1 = new List <PackingListDetailViewModel>(); var packingListDetailModel2 = new List <PackingListDetailViewModel>(); var packingListDetailModel3 = new List <PackingListDetailViewModel>(); decimal?totalPQty = 0; decimal?totalRQty = 0; var lists = packingListDetailAll .Where(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).ToList(); foreach (var item in lists) { var packingItem1 = new PackingListDetailViewModel(); packingItem1.Receive_No = item.Receive_No; packingItem1.Order_Size = item.Order_Size; packingItem1.Model_Size = item.Model_Size; packingItem1.Tool_Size = item.Tool_Size; packingItem1.Spec_Size = item.Spec_Size; packingItem1.MO_Qty = item.MO_Qty; packingItem1.Purchase_Qty = item.Purchase_Qty; packingItem1.Received_Qty = item.Received_Qty; packingItem1.Act = 0; foreach (var itemByToolSize in BalByToolSize) { if (itemByToolSize.Tool_Size.Trim() == item.Tool_Size.Trim()) { packingItem1.Bal = itemByToolSize.Bal; } } totalPQty = totalPQty + item.Purchase_Qty; totalRQty = totalRQty + item.Received_Qty; packingListDetailModel.Add(packingItem1); } //----------------- Xử lý mảng dữ liệu cho 1 số dòng cùng tool size.----------------// // List các Tool Size mà có nhiều Order Size trong bảng Packing List Detail var toolSizeMoreOrderSize = lists.Where(x => x.Tool_Size.Trim() != x.Order_Size.Trim()).Select(x => x.Tool_Size).Distinct().ToList(); if (toolSizeMoreOrderSize.Count() > 0) { foreach (var itemToolSize in toolSizeMoreOrderSize) { var model1 = packingListDetailModel.Where(x => x.Tool_Size.Trim() == itemToolSize.Trim()) .GroupBy(x => x.Tool_Size).Select(x => new { Purchase_Qty = x.Sum(cl => cl.Purchase_Qty), Received_Qty = x.Sum(cl => cl.Received_Qty), Act = x.Sum(cl => cl.Act), Bal = x.First().Bal }).FirstOrDefault(); var packingDetailByToolSize = packingListDetailModel .Where(x => x.Tool_Size.Trim() == itemToolSize.Trim()).ToList(); for (var i = 0; i < packingDetailByToolSize.Count; i++) { if (i != 0) { packingDetailByToolSize[i].Purchase_Qty = null; packingDetailByToolSize[i].Received_Qty = null; packingDetailByToolSize[i].Act = null; packingDetailByToolSize[i].Bal = null; } else { packingDetailByToolSize[i].Purchase_Qty = model1.Purchase_Qty; packingDetailByToolSize[i].Received_Qty = model1.Received_Qty; packingDetailByToolSize[i].Act = model1.Act; packingDetailByToolSize[i].Bal = model1.Bal; } } } } var count = packingListDetailModel.Count(); if (count > 0 && count <= 8) { packingListDetailModel1 = packingListDetailModel; } else if (count > 8 && count <= 16) { for (int i = 0; i < 8; i++) { packingListDetailModel1.Add(packingListDetailModel[i]); } for (int i = 8; i < count; i++) { packingListDetailModel2.Add(packingListDetailModel[i]); } } else if (count > 16) { for (int i = 0; i < 8; i++) { packingListDetailModel1.Add(packingListDetailModel[i]); } for (int i = 8; i < 16; i++) { packingListDetailModel2.Add(packingListDetailModel[i]); } for (int i = 16; i < count; i++) { packingListDetailModel3.Add(packingListDetailModel[i]); } } // Lấy dữ liệu show phần Suggested Location Material Form var transactionMain = await _repoTransactionMain.GetAll().ToListAsync(); var transactionMain1 = transactionMain.Where(x => x.QRCode_ID.Trim() == data.QRCode_ID.Trim() && (x.Transac_Type == "I" || x.Transac_Type == "M" || x.Transac_Type == "R") && x.Can_Move.Trim() == "Y"); var suggestedReturn1 = transactionMain1.Select(x => new { rack_Location = x.Rack_Location }).Distinct().ToList(); // Lấy dữ liệu show phần Suggested Location Sorting Form var transactionMain2 = transactionMain .Where(x => x.QRCode_ID.Trim() == data.QRCode_ID.Trim() && x.Transac_Type == "I" && x.Can_Move.Trim() == "Y"); var suggestedReturn2 = transactionMain2.Select(x => new { rack_Location = x.Rack_Location }).Distinct().ToList(); var result = new { totalPQty, totalRQty, packingListDetailModel1, packingListDetailModel2, packingListDetailModel3, suggestedReturn1, suggestedReturn2, }; return(result); }