// ------------------Hàm lấy chi tiết của 1 Receive_No.------------------------------------------------------------ public async Task <List <ReceiveNoDetail> > ReceiveNoDetails(string receive_No) { var packingListDetail = await _repoPackingListDetail.GetAll() .Where(x => x.Receive_No.Trim() == receive_No.Trim()).ToListAsync(); var listData = packingListDetail.Select(x => new ReceiveNoDetail() { Order_Size = x.Order_Size, Purchase_Qty = x.Purchase_Qty, Received_Qty = x.Received_Qty, }).ToList(); return(listData); }
public async Task<bool> AddListQRCode(List<string> listReceiveNo) { var checkCreate = true; Random ran = new Random(); foreach (var item in listReceiveNo) { // Tạo QrCodeMain để thêm vào database var qrCodeDto = new QRCode_Main_Dto(); var packing = await _repoPacking.GetAll().Where(x => x.Receive_No.Trim() == item.Trim()).FirstOrDefaultAsync(); packing.Generated_QRCode = "Y"; int so = ran.Next(100,999); string qrCodeId = "B" + packing.MO_No.Trim() + so.ToString(); qrCodeDto.QRCode_ID = qrCodeId; qrCodeDto.Receive_No = packing.Receive_No.Trim(); qrCodeDto.QRCode_Version = 1; qrCodeDto.Valid_Status = "Y"; qrCodeDto.Is_Scanned = "N"; qrCodeDto.QRCode_Type = packing.Sheet_Type.Trim(); await _repoPacking.SaveAll(); var qrCodeMain = _mapper.Map<WMSB_QRCode_Main>(qrCodeDto); _repoQrcode.Add(qrCodeMain); // Tạo QrCodeDetail để thêm vào database var listPackingDetail = await _repoPackingDetail.GetAll().Where(x => x.Receive_No.Trim() == item.Trim()).ToListAsync(); foreach (var packingItem in listPackingDetail) { var qrCodeDetailDto = new QRCode_Detail_Dto(); qrCodeDetailDto.QRCode_ID = qrCodeId; qrCodeDetailDto.QRCode_Version = 1; qrCodeDetailDto.Order_Size = packingItem.Order_Size; qrCodeDetailDto.Model_Size = packingItem.Model_Size; qrCodeDetailDto.Tool_Size = packingItem.Tool_Size; qrCodeDetailDto.Spec_Size = packingItem.Spec_Size; qrCodeDetailDto.Qty = packingItem.Received_Qty; qrCodeDetailDto.Updated_By = "Emma"; var qrCodeDetail = _mapper.Map<WMSB_QRCode_Detail>(qrCodeDetailDto); _repoQrCodeDetail.Add(qrCodeDetail); if (!await _repoQrCodeDetail.SaveAll()) { checkCreate = false; break; } } } await _repoQrcode.SaveAll(); return checkCreate; }
// ---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); }