public async Task <Output_Dto> GetByQrCodeIdByCollectionTransferForm(string qrCodeId) { string message = "No data!"; // biến qrcodeid là sheet no của bảng materialsheetsize, dựa theo mã đó lấy ra listmaterialsheetsize là danh sánh đơn output ra var listTransacNo = await _repoTransferForm.FindAll(x => x.Collect_Trans_No.Trim() == qrCodeId.Trim()).Select(x => x.Transac_No).ToListAsync(); // dữ liệu output cần hiển thị: trong bảng tranasaction main, transaction detail ... var listOutput = await GetListOutputInfo(listTransacNo, qrCodeId); var outputTotalNeedQty = await GetOutputNeedQty(listTransacNo); // dữ liệu cần lấy ra để hiển thị: listoutputmain là trong bảng transaction main với type bằng I, R, M và listmaterialsheetsize là số lượng cần output ra của đơn Output_Dto result = new Output_Dto(); result.Outputs = listOutput; result.OutputTotalNeedQty = outputTotalNeedQty; result.Message = message; return(result); }
public async Task <PagedList <Transfer_Form_Generate_Dto> > GetTransferFormPrint(string fromTime, string toTime, string moNo, string isRelease, string t2Supplier, string t3Supplier, int pageNumber = 1, int pageSize = 10) { var transferForm = _transferFormRepository.FindAll(x => x.Is_Release == isRelease); var transactionMain = _transactionMainRepo.FindAll(); var qrCodeMain = _qRCodeMainRepository.FindAll(); var packingList = _packingListRepository.FindAll(); if (!string.IsNullOrEmpty(fromTime) && !string.IsNullOrEmpty(toTime) && isRelease == "Y") { DateTime t1 = Convert.ToDateTime(fromTime); DateTime t2 = Convert.ToDateTime(toTime + " 23:59:59"); transferForm = transferForm.Where(x => x.Release_Time >= t1 && x.Release_Time <= t2); } if (!string.IsNullOrEmpty(t3Supplier)) { transferForm = transferForm.Where(x => x.T3_Supplier.Trim() == t3Supplier.Trim()); } var data = transferForm.OrderByDescending(x => x.Generate_Time).GroupJoin( transactionMain, e => e.Transac_No, f => f.Transac_No, (e, f) => new { e, f }) .SelectMany( g => g.f.DefaultIfEmpty(), (g, h) => new { g.e, h }) .GroupJoin( qrCodeMain, x => new { QRCode_ID = x.h.QRCode_ID, QRCode_Version = x.h.QRCode_Version }, y => new { QRCode_ID = y.QRCode_ID, QRCode_Version = y.QRCode_Version }, (x, y) => new { x, y }) .SelectMany( z => z.y.DefaultIfEmpty(), (z, t) => new { z.x, t }) .GroupJoin( packingList, a => a.t.Receive_No, b => b.Receive_No, (a, b) => new { a, b }) .SelectMany( c => c.b.DefaultIfEmpty(), (c, d) => new Transfer_Form_Generate_Dto { Transac_Time = c.a.x.h.Transac_Time, Update_Time = c.a.x.e.Update_Time, Release_Time = c.a.x.e.Release_Time, Collect_Trans_No = c.a.x.e.Collect_Trans_No, Is_Release = c.a.x.e.Is_Release, Material_ID = c.a.x.h.Material_ID, Material_Name = c.a.x.h.Material_Name, MO_No = c.a.x.h.MO_No, MO_Seq = c.a.x.h.MO_Seq, QRCode_ID = c.a.x.h.QRCode_ID, Transac_No = c.a.x.h.Transac_No, T3_Supplier = d.T3_Supplier, T3_Supplier_Name = d.T3_Supplier_Name, Subcon_ID = d.Subcon_ID, Subcon_Name = d.Subcon_Name, Supplier_ID = d.Supplier_ID, Supplier_Name = d.Supplier_Name, Model_Name = d.Model_Name, Model_No = d.Model_No, Article = d.Article, Custmoer_Part = _cacheRepository.GetCustmoerPart(d.MO_No, d.MO_Seq, d.Material_ID, d.Purchase_No), Custmoer_Name = _cacheRepository.GetCustmoerName(d.MO_No, d.MO_Seq, d.Material_ID, d.Purchase_No), Purchase_Qty = _packingListDetailRepository.SumPurchaseQtyByReceiveNo(d.Receive_No), Transacted_Qty = c.a.x.h.Transacted_Qty, Email = _settingSupplierRepository.GetEmailByT3Supplier(d.T3_Supplier, d.Subcon_ID) }); if (!string.IsNullOrEmpty(moNo)) { data = data.Where(x => x.MO_No == moNo); } if (!string.IsNullOrEmpty(t2Supplier)) { data = data.Where(x => x.Supplier_ID == t2Supplier); } if (!string.IsNullOrEmpty(fromTime) && !string.IsNullOrEmpty(toTime) && isRelease == "N") { DateTime t1 = Convert.ToDateTime(fromTime); DateTime t2 = Convert.ToDateTime(toTime + " 23:59:59"); data = data.Where(x => x.Transac_Time >= t1 && x.Transac_Time <= t2); } var dataList = data.ToList(); List <Transfer_Form_Generate_Dto> resultList = new List <Transfer_Form_Generate_Dto>(); var dataGroup = dataList.GroupBy(x => x.Collect_Trans_No); foreach (var item in dataGroup) { var itemDataGroup = dataList.Where(x => x.Collect_Trans_No == item.Key).Select(x => new Transfer_Form_Generate_Dto { Update_Time = x.Update_Time, Collect_Trans_No = x.Collect_Trans_No, Is_Release = x.Is_Release, Material_ID = x.Material_ID, Material_Name = x.Material_Name, MO_No = x.MO_No, MO_Seq = x.MO_Seq, Transac_No = x.Transac_No, T3_Supplier = x.T3_Supplier, T3_Supplier_Name = x.T3_Supplier_Name, Supplier_ID = x.Supplier_ID, Supplier_Name = x.Supplier_Name, Email = x.Email, Release_Time = x.Release_Time, Subcon_ID = x.Subcon_ID, Subcon_Name = x.Subcon_Name, Custmoer_Name = x.Custmoer_Name, Custmoer_Part = x.Custmoer_Part, Model_Name = x.Model_Name, Model_No = x.Model_No, Article = x.Article, Purchase_Qty = dataList.Where(x => x.Collect_Trans_No == item.Key).Sum(x => x.Purchase_Qty), Transacted_Qty = dataList.Where(x => x.Collect_Trans_No == item.Key).Sum(x => x.Transacted_Qty), }).FirstOrDefault(); resultList.Add(itemDataGroup); } resultList = resultList.OrderByDescending(x => x.Update_Time).ThenBy(x => x.MO_No).ThenBy(x => x.MO_Seq).ThenBy(x => x.Material_ID).ToList(); return(await Task.FromResult(PagedList <Transfer_Form_Generate_Dto> .Create(resultList, pageNumber, pageSize, false))); }