public async Task<QRCodePrint_Dto> GetQrCodePrint(string qrCodeId, int qrCodeVersion) { var qrCodeModel = _repoQrcode.FindSingle(x => x.QRCode_ID.Trim() == qrCodeId.Trim() && x.QRCode_Version == qrCodeVersion); var packingListModel = await _repoPacking.FindAll(x => x.Receive_No.Trim() == qrCodeModel.Receive_No.Trim()).ProjectTo<Packing_List_Dto>(_configMapper).FirstOrDefaultAsync(); var transactionMainModel = _repoTransactionMain.FindSingle(x => x.QRCode_ID.Trim() == qrCodeModel.QRCode_ID.Trim() && x.QRCode_Version == qrCodeModel.QRCode_Version && (x.Transac_Type.Trim() == "I" || x.Transac_Type.Trim() == "R")); var transactionDetailModel = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == transactionMainModel.Transac_No.Trim()).ProjectTo<TransferLocationDetail_Dto>(_configMapper).OrderBy(x => x.Tool_Size).ToListAsync(); // Lấy ra những thuộc tính cần in QRCodePrint_Dto result = new QRCodePrint_Dto(); result.TransactionDetailByQrCodeId = transactionDetailModel; result.PackingListByQrCodeId = packingListModel; result.RackLocation = transactionMainModel.Rack_Location; return result; }
public async Task <List <OutputPrintQrCode_Dto> > PrintByQRCodeIDAgain(List <QrCodeIDVersion> ListParamPrintQrCodeAgain) { List <OutputPrintQrCode_Dto> listResult = new List <OutputPrintQrCode_Dto>(); foreach (var paramPrintQrCodeAgain in ListParamPrintQrCodeAgain) { // hàm lấy ra thông tin qrcode main, mấy thông tin chính var qrCodeModel = await GetQrCodeInfor(paramPrintQrCodeAgain.QRCode_ID, paramPrintQrCodeAgain.MO_Seq); // ở dưới là lấy ra thông tin chi tiết của qrcode đó var qrCodeMan = _repoQRCodeMain.FindSingle(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() && x.QRCode_Version == paramPrintQrCodeAgain.QRCode_Version); var transactionMainTypeR = await _repoTransactionMain.FindAll(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() && x.QRCode_Version == paramPrintQrCodeAgain.QRCode_Version && x.Can_Move == "Y").FirstOrDefaultAsync(); var transactionDetailsTypeR = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == transactionMainTypeR.Transac_No.Trim()).ToListAsync(); var transactionMain = await _repoTransactionMain.FindAll(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() && x.Transac_Type == "I").FirstOrDefaultAsync(); var transactionDetails = await _repoTransactionDetail .FindAll(x => x.Transac_No.Trim() == transactionMain.Transac_No.Trim()).ToListAsync(); var listsPackingListDetail = await _repoPackingListDetail.FindAll() .Where(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).ToListAsync(); //--------- phần xuất thêm giá trị đã output var transactionMainOutputs = await _repoTransactionMain.FindAll(x => x.Purchase_No.Trim() == transactionMain.Purchase_No.Trim() && x.MO_No.Trim() == transactionMain.MO_No.Trim() && x.MO_Seq.Trim() == transactionMain.MO_Seq.Trim() && x.Material_ID == transactionMain.Material_ID && x.Transac_Type.Trim() == "O").ToListAsync(); List <WMSB_Transaction_Detail> transactionDetailOutputs = new List <WMSB_Transaction_Detail>(); if (transactionMainOutputs.Count() > 0) { foreach (var item in transactionMainOutputs) { var transactionDetailOutput = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == item.Transac_No.Trim()).ToListAsync(); transactionDetailOutputs.AddRange(transactionDetailOutput); } } var transactionDetailOutputGroupBy = transactionDetailOutputs.GroupBy(x => new { x.Tool_Size, x.Order_Size }).Select(x => new { OutQty = x.Sum(y => y.Trans_Qty), Tool_Size = x.Key.Tool_Size, Order_Size = x.Key.Order_Size }).ToList(); //------------ var packingListDetailModel = new List <PackingListDetailViewModel>(); foreach (var item in listsPackingListDetail) { var packingItem = new PackingListDetailViewModel(); packingItem.Receive_No = item.Receive_No; packingItem.Order_Size = item.Order_Size; packingItem.Model_Size = item.Model_Size; packingItem.Tool_Size = item.Tool_Size; packingItem.Spec_Size = item.Spec_Size; packingItem.MO_Qty = item.MO_Qty; packingItem.Purchase_Qty = item.Purchase_Qty; foreach (var item1 in transactionDetails) { if (item1.Tool_Size.Trim() == item.Tool_Size.Trim() && item1.Order_Size.Trim() == item.Order_Size.Trim()) { packingItem.Received_Qty = item1.Qty; packingItem.Bal = item1.Untransac_Qty; } } foreach (var item3 in transactionDetailsTypeR) { if (item3.Tool_Size.Trim() == item.Tool_Size.Trim() && item3.Order_Size.Trim() == item.Order_Size.Trim()) { packingItem.Act = item3.Instock_Qty; } } if (transactionDetailOutputGroupBy.Count() > 0) { foreach (var item2 in transactionDetailOutputGroupBy) { if (item2.Tool_Size.Trim() == item.Tool_Size.Trim() && item2.Order_Size.Trim() == item.Order_Size.Trim()) { packingItem.OutQty = item2.OutQty; } } } else { packingItem.OutQty = 0; } packingListDetailModel.Add(packingItem); } packingListDetailModel = packingListDetailModel.OrderBy(x => x.Tool_Size).ThenBy(x => x.Order_Size).ToList(); // List các Tool Size mà có nhiều Order Size trong bảng Packing List Detail var toolSizeMoreOrderSize = packingListDetailModel.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.Sum(cl => cl.Bal), OutQty = x.Sum(cl => cl.OutQty) }).FirstOrDefault(); var packingListByToolSize = packingListDetailModel .Where(x => x.Tool_Size.Trim() == itemToolSize.Trim()).ToList(); for (var i = 0; i < packingListByToolSize.Count; i++) { if (i != 0) { packingListByToolSize[i].Purchase_Qty = null; packingListByToolSize[i].Received_Qty = null; packingListByToolSize[i].Act = null; packingListByToolSize[i].Bal = null; packingListByToolSize[i].OutQty = null; } else { packingListByToolSize[i].Purchase_Qty = model1.Purchase_Qty; packingListByToolSize[i].Received_Qty = model1.Received_Qty; packingListByToolSize[i].Act = model1.Act; packingListByToolSize[i].Bal = model1.Bal; packingListByToolSize[i].OutQty = model1.OutQty; } } } } OutputPrintQrCode_Dto result = new OutputPrintQrCode_Dto { QrCodeModel = qrCodeModel, PackingListDetail = packingListDetailModel, RackLocation = transactionMainTypeR.Rack_Location }; listResult.Add(result); } return(listResult); }
// ---Phần in QrCodeId khi vào Menu 2.QrGenerate => Print (Material Form)-------// public async Task <object> FindByQrCodeID(QrCodeIDVersion data) { var qrCodeMan = _repoQrcode.FindSingle(x => x.QRCode_ID.Trim() == data.QRCode_ID.Trim() && x.QRCode_Version == data.QRCode_Version); // Tìm kiếm Purchase và Sheet_Type của qrcodeid với version đó. var packingListFind = _repoPackingList.FindSingle(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()); // Tìm List ReceiveNo tương ứng với Purchase và Sheet_Type ở trên var ReceiveNoList = await _repoPackingList.FindAll(x => x.Purchase_No.Trim() == packingListFind.Purchase_No.Trim() && x.Material_ID.Trim() == packingListFind.Material_ID.Trim() && x.Sheet_Type.Trim() == packingListFind.Sheet_Type.Trim() && x.MO_Seq == packingListFind.MO_Seq && x.MO_No.Trim() == data.MO_No.Trim() && x.Receive_Date <= packingListFind.Receive_Date) .Select(x => x.Receive_No).ToListAsync(); var packingDetailList = new List <WMSB_PackingList_Detail>(); foreach (var item in ReceiveNoList) { var packingdetailitem = await _repoPackingListDetail.FindAll(x => x.Receive_No.Trim() == item.Trim()).ToListAsync(); 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 = await _repoPackingListDetail.FindAll(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).ToListAsync(); 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; } } } } // Sắp xếp lại theo Tool-Size và Order_Size theo thứ tự tăng dần. packingListDetailModel = packingListDetailModel .OrderBy(x => decimal.Parse(x.Tool_Size)).ThenBy(x => decimal.Parse(x.Order_Size)).ToList(); 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]); } } var result = new { totalPQty, totalRQty, packingListDetailModel1, packingListDetailModel2, packingListDetailModel3, }; return(result); }