public async Task <MissingPrint_Dto> GetMaterialPrint(string missingNo) { var materialMissingModel = await _repoMaterialMissing.FindAll(x => x.Missing_No.Trim() == missingNo.Trim()).ProjectTo <Material_Dto>(_configMapper).FirstOrDefaultAsync(); var transactionMainModel = _repoTransactionMain.FindSingle(x => x.Missing_No.Trim() == missingNo.Trim() && x.Transac_Type.Trim() == "I"); var transactionDetailByMissingNo = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == transactionMainModel.Transac_No.Trim()).ProjectTo <TransferLocationDetail_Dto>(_configMapper).OrderBy(x => x.Tool_Size).ToListAsync(); var materialPurchaseModel = await _repoMaterialView.FindAll().Where(x => x.Plan_No.Trim() == materialMissingModel.MO_No.Trim() && x.Purchase_No.Trim() == materialMissingModel.Purchase_No.Trim() && x.Mat_.Trim() == materialMissingModel.Material_ID.Trim()).FirstOrDefaultAsync(); materialMissingModel.Custmoer_Name = materialPurchaseModel.Custmoer_Name; // Lấy ra những thuộc tính cần in MissingPrint_Dto result = new MissingPrint_Dto(); result.MaterialMissing = materialMissingModel; result.TransactionDetailByMissingNo = transactionDetailByMissingNo; return(result); }
public async Task <List <ReceiveNoMain> > UpdateMaterial(List <OrderSizeByBatch> data) { var Purchase_No = data[0].Purchase_No; // --------------------------------------------------------------------------------------------// if (data[0].Missing_No == "") { // --------Update lại Accumlated_In_Qty theo Purchase_No,Order_Size và Mo_Seq ở bảng Material_Purchase----// foreach (var item in data) { foreach (var item1 in item.Purchase_Qty) { var materialItem = await _repoPurchase.FindAll() .Where(x => x.Purchase_No.Trim() == Purchase_No.Trim() && x.Order_Size == item1.Order_Size && x.MO_Seq == item.MO_Seq).FirstOrDefaultAsync(); // materialItem.Accumlated_In_Qty = item1.Accumlated_In_Qty; // Số lượng bằng số lượng nhận hiện tại + số lượng vừa mới nhận vào. materialItem.Accumlated_In_Qty = materialItem.Accumlated_In_Qty + item1.Received_Qty; await _repoPurchase.SaveAll(); } } //------------------------- Update giá trị Status--------------------------------------------// foreach (var item in data) { await this.UpdateStatusMaterial(item.Purchase_No, item.MO_Seq, item.Missing_No); } await _repoPurchase.SaveAll(); } else { // Update lại Accumlated_In_Qty theo Purchase_No,Order_Size và Mo_Seq ở bảng Material_Missing foreach (var item in data) { foreach (var item1 in item.Purchase_Qty) { var materialItem = await _repoMissing.FindAll() .Where(x => x.Purchase_No.Trim() == Purchase_No.Trim() && x.Order_Size == item1.Order_Size && x.MO_Seq == item.MO_Seq).FirstOrDefaultAsync(); materialItem.Accumlated_In_Qty = item1.Accumlated_In_Qty; } } // Update lại Status foreach (var item in data) { await this.UpdateStatusMaterial(item.Purchase_No, item.MO_Seq, item.Missing_No); } await _repoMissing.SaveAll(); } //------------------------Thêm vào 2 bảng Packing_List và Packing_List_Detail------------------// var ReceiveNoMain = new List <ReceiveNoMain>(); foreach (var item in data) { // Check xem có tiến hành thêm hay ko var checkAdd = false; foreach (var item1 in item.Purchase_Qty) { // Kiểm tra nếu tồn tại Received_Qty lớn hơn 0,có nghĩa là tồn tại 1 Order_Size trong batch đó có nhận hàng if (item1.Received_Qty > 0) { checkAdd = true; break; } } // Tiến hành thêm vào bảng Packing_List và Packing_List_Detail if (checkAdd == true) { var packing_List = new Packing_List_Dto(); if (item.Missing_No == string.Empty) { packing_List.Sheet_Type = "R"; } else { packing_List.Sheet_Type = "M"; } packing_List.Missing_No = item.Missing_No; packing_List.Supplier_ID = item.Supplier_ID; packing_List.Supplier_Name = item.Supplier_Name; packing_List.MO_No = item.MO_No; packing_List.Purchase_No = item.Purchase_No; packing_List.MO_Seq = item.MO_Seq; packing_List.Delivery_No = item.Delivery_No; packing_List.Material_ID = item.Material_ID; packing_List.Material_Name = item.Material_Name; packing_List.Model_No = item.Model_No; packing_List.Model_Name = item.Model_Name; packing_List.Article = item.Article; packing_List.Subcon_ID = item.Subcon_No; packing_List.Subcon_Name = item.Subcon_Name; packing_List.T3_Supplier = item.T3_Supplier; packing_List.T3_Supplier_Name = item.T3_Supplier_Name; packing_List.Generated_QRCode = "N"; packing_List.Receive_Date = DateTime.Now; packing_List.Updated_By = "Phi Long"; packing_List.Receive_No = this.RandomString(2); // Tạo ra thông tin của 1 Receive No var ReceiveNoItem = new ReceiveNoMain(); ReceiveNoItem.MO_No = item.MO_No; ReceiveNoItem.Purchase_No = item.Purchase_No; ReceiveNoItem.Receive_No = packing_List.Receive_No; ReceiveNoItem.MO_Seq = item.MO_Seq; ReceiveNoItem.Receive_Date = packing_List.Receive_Date; ReceiveNoItem.Sheet_Type = packing_List.Sheet_Type; ReceiveNoItem.Updated_By = packing_List.Updated_By; ReceiveNoItem.Purchase_Qty = 0; ReceiveNoItem.Accumated_Qty = 0; await _packingListService.Add(packing_List); foreach (var item2 in item.Purchase_Qty) { var packing_List_detail = new Packing_List_Detail_Dto(); packing_List_detail.Receive_No = packing_List.Receive_No; packing_List_detail.Order_Size = item2.Order_Size; packing_List_detail.Model_Size = item2.Model_Size; packing_List_detail.Tool_Size = item2.Tool_Size; packing_List_detail.Spec_Size = item2.Spec_Size; packing_List_detail.MO_Qty = item2.MO_Qty; packing_List_detail.Purchase_Qty = item2.Purchase_Qty_Const; packing_List_detail.Received_Qty = item2.Received_Qty; packing_List_detail.Updated_Time = DateTime.Now; packing_List_detail.Updated_By = "Phi Long"; ReceiveNoItem.Purchase_Qty = ReceiveNoItem.Purchase_Qty + item2.Purchase_Qty_Const; ReceiveNoItem.Accumated_Qty = ReceiveNoItem.Accumated_Qty + item2.Received_Qty; await _packingListDetailService.Add(packing_List_detail); } ReceiveNoMain.Add(ReceiveNoItem); } } return(ReceiveNoMain); }
public async Task <object> MaterialMerging(MaterialMainViewModel model) { var listMaterial = new List <Material_Dto>(); if (model.Missing_No != "") { listMaterial = await _repoMissing.FindAll(x => x.Purchase_No.Trim() == model.Purchase_No.Trim() && x.Missing_No.Trim() == model.Missing_No.Trim() && x.MO_No.Trim() == model.MO_No.Trim()) .ProjectTo <Material_Dto>(_configMapper) .ToListAsync(); } else { listMaterial = await _repoPurchase.FindAll(x => x.Purchase_No.Trim() == model.Purchase_No.Trim() && x.MO_No.Trim() == model.MO_No.Trim() && x.Biz_Tflag.Trim() != "D" && (x.MO_Qty != 0 || x.Purchase_Qty != 0) ) .ProjectTo <Material_Dto>(_configMapper) .ToListAsync(); } listMaterial.OrderByDescending(x => x.MO_Seq); var OrderSizeGroup = listMaterial.GroupBy(x => x.Order_Size).Select(x => x.Key); OrderSizeGroup = OrderSizeGroup.OrderBy(x => decimal.Parse(x)).ToList(); var listBatch = listMaterial.GroupBy(x => x.MO_Seq).Select(y => new { MO_Seq = y.First().MO_Seq }).ToList(); var list3 = new List <OrderSizeByBatch>(); foreach (var item in listBatch) { var item1 = new OrderSizeByBatch(); item1.MO_Seq = item.MO_Seq; item1.Purchase_No = model.Purchase_No; item1.Missing_No = model.Missing_No; item1.Material_ID = model.Material_ID; item1.Material_Name = model.Material_Name; item1.Model_No = model.Model_No; item1.Model_Name = model.Model_Name; item1.MO_No = model.MO_No; item1.Article = model.Article; item1.Supplier_ID = model.Supplier_ID; item1.Supplier_Name = model.Supplier_Name; item1.Subcon_No = model.Subcon_No; item1.Subcon_Name = model.Subcon_Name; item1.T3_Supplier = model.T3_Supplier; item1.T3_Supplier_Name = model.T3_Supplier_Name; // ---- Start Check xem Batch này đã insert đủ hết chưa.----- item1.CheckInsert = "1"; foreach (var item4 in listMaterial) { if (item4.MO_Seq == item.MO_Seq) { if (item4.Accumlated_In_Qty != item4.Purchase_Qty) { item1.CheckInsert = "0"; break; } } } // -----------------------------End------------------------ var item3 = new List <OrderSizeAccumlate>(); foreach (var orderSize in OrderSizeGroup) { var materialByBathOrderSize = listMaterial .Where(x => x.Order_Size.Trim() == orderSize.Trim() && x.MO_Seq == item.MO_Seq); if (materialByBathOrderSize.Count() > 0) { foreach (var item2 in materialByBathOrderSize) { var item4 = new OrderSizeAccumlate(); item4.Order_Size = item2.Order_Size; item4.Model_Size = item2.Model_Size; item4.Tool_Size = item2.Tool_Size; item4.Spec_Size = item2.Spec_Size; item4.Purchase_Qty_Const = item2.Purchase_Qty; item4.MO_Qty = item2.MO_Qty; item4.Purchase_Qty = item2.Purchase_Qty - item2.Accumlated_In_Qty; item4.Accumlated_In_Qty = item2.Accumlated_In_Qty; item4.Received_Qty = 0; item3.Add(item4); item1.Purchase_Qty = item3; } } else { var item4 = new OrderSizeAccumlate(); item4.Order_Size = orderSize; item3.Add(item4); } } list3.Add(item1); } // -------------------------------------------------------------------------------------------// var list1 = listMaterial.GroupBy(l => l.Order_Size) .Select(cl => new { Tool_Size = cl.First().Tool_Size, Order_Size = cl.First().Order_Size, Accumlated_In_Qty = cl.Sum(c => c.Accumlated_In_Qty), Delivery_Qty_Batches = cl.Sum(x => x.Accumlated_In_Qty), Purchase_Qty = cl.Sum(c => c.Purchase_Qty), Delivery_Qty = cl.Sum(c => c.Purchase_Qty) - cl.Sum(c => c.Accumlated_In_Qty) }).ToList(); var list2 = listMaterial.GroupBy(x => new { x.Order_Size, x.Purchase_Qty, x.MO_Seq }) .Select(y => new { Order_Size = y.First().Order_Size, Purchase_Qty = y.First().Purchase_Qty, MO_Seq = y.First().MO_Seq, }); var list4 = new List <MaterialMergingViewMode>(); foreach (var orderSize in OrderSizeGroup) { var list5 = list1.Where(x => x.Order_Size.Trim() == orderSize.Trim()); foreach (var item in list5) { var arrayItem = new MaterialMergingViewMode(); arrayItem.Tool_Size = item.Tool_Size; arrayItem.Order_Size = item.Order_Size; arrayItem.Purchase_Qty = item.Purchase_Qty; arrayItem.Accumlated_In_Qty = item.Accumlated_In_Qty; arrayItem.Delivery_Qty = item.Delivery_Qty; arrayItem.Delivery_Qty_Batches = item.Delivery_Qty_Batches; var array1 = new List <BatchQtyItem>(); foreach (var item1 in list2) { if (item1.Order_Size.Trim() == item.Order_Size.Trim()) { var item2 = new BatchQtyItem(); item2.MO_Seq = item1.MO_Seq; item2.Purchase_Qty = item1.Purchase_Qty; array1.Add(item2); arrayItem.Purchase_Qty_Item = array1; } } list4.Add(arrayItem); } } var totalByBatch = new List <TotalQtyOfBatch>(); foreach (var item in list3) { var totalQty = item.Purchase_Qty.Sum(x => x.Purchase_Qty); var itemTotalQty = new TotalQtyOfBatch(); itemTotalQty.Total = totalQty; itemTotalQty.MO_Seq = item.MO_Seq; totalByBatch.Add(itemTotalQty); } var listTotalQty = new TotalQty(); listTotalQty.TotalPurchaseQty = list4.Sum(x => x.Purchase_Qty); listTotalQty.TotalAccumated_Qty = list4.Sum(x => x.Accumlated_In_Qty); listTotalQty.TotalDeliveryQty = list4.Sum(x => x.Delivery_Qty); // --------------------------------------End----------------------------------------// var result = new { list3, list4, totalByBatch, listTotalQty }; return(result); }