public ActionResult GetBooksReqDetails(string District, string CircleId, string categoryId, string languageId, string ChallanId, bool isPartialViewRequest = false) { InvoiceCumChallan lst_invCumChal = new InvoiceCumChallan(); try { Int16 AccadYear = Convert.ToInt16(GlobalSettings.oUserData.AcademicYearId); DataTable dtReqDtl = new DataTable(); if (Convert.ToInt64(ChallanId) != 0) { dtReqDtl = objDbTrx.GetChallanDetailsById(Convert.ToInt64(ChallanId)); } DataTable dtTransaction = objDbTrx.GetChallanListDtlForBarcode(CircleId, categoryId, languageId, ChallanId, AccadYear); DataTable dt = objDbTrx.GetBinderDtlListByChallanIdOnly(ChallanId); List <InvoiceCumChallanList> ObjlstInvCumCha = new List <InvoiceCumChallanList>(); if (dtTransaction.Rows.Count > 0) { for (int iCnt = 0; iCnt < dtTransaction.Rows.Count; iCnt++) { InvoiceCumChallanList icc = new InvoiceCumChallanList(); icc.ClassName = Convert.ToString(dtTransaction.Rows[iCnt]["Class"].ToString()); icc.Book_Code = Convert.ToString(dtTransaction.Rows[iCnt]["Book_Code"].ToString()); icc.Common_Book_Code = Convert.ToString(dtTransaction.Rows[iCnt]["Common_Book_Code"].ToString()); icc.Book_Name = Convert.ToString(dtTransaction.Rows[iCnt]["book_name"].ToString()); icc.NetReqQty = Convert.ToInt32(dtTransaction.Rows[iCnt]["NetReqQtyAfterStockDeduction"].ToString()) > default(int) ? Convert.ToInt32(dtTransaction.Rows[iCnt]["NetReqQtyAfterStockDeduction"].ToString()) : default(int); icc.AlreadyShippedQty = Convert.ToInt32(dtTransaction.Rows[iCnt]["AlreadyShipped"].ToString()); icc.QtyShipped = 0; icc.Cartoon = ""; //icc.Cartoon = !string.IsNullOrWhiteSpace(dtTransaction.Rows[iCnt]["LOT"].ToString()) ? string.Format("Lot - {0}, Books per lot - {1}", dtTransaction.Rows[iCnt]["LOT"].ToString(), dtTransaction.Rows[iCnt]["REQ_QTY"].ToString()) : ""; //icc.Lot = dtTransaction.Rows[iCnt]["LOT"].ToString(); //icc.TotBooksPerLot = icc.Cartoon = !string.IsNullOrWhiteSpace(dtTransaction.Rows[iCnt]["LOT"].ToString()) ? string.Format("Lot - {0}, Books per lot - {1}", dtTransaction.Rows[iCnt]["LOT"].ToString(), dtTransaction.Rows[iCnt]["REQ_QTY"].ToString()) : ""; icc.TotalLot = Convert.ToInt32(dtTransaction.Rows[iCnt]["LOT"] != null && !string.IsNullOrWhiteSpace(dtTransaction.Rows[iCnt]["LOT"].ToString()) ? dtTransaction.Rows[iCnt]["LOT"].ToString() : default(int).ToString()); icc.Remarks = ""; if (dtReqDtl != null && dtReqDtl.Rows.Count > default(int)) { for (int jCnt = 0; jCnt < dtReqDtl.Rows.Count; jCnt++) { if (dtTransaction.Rows[iCnt]["Book_Code"].ToString() == dtReqDtl.Rows[jCnt]["Book_Code"].ToString()) { icc.QtyShipped = Convert.ToInt32(dtReqDtl.Rows[jCnt]["QtyShippedQty"].ToString()); icc.Cartoon = dtReqDtl.Rows[jCnt]["Cartoon"].ToString(); // icc.RemarksId = dtReqDtl.Rows[jCnt]["RemarksID"].ToString(); break; } } } try { icc.RemainBal = (icc.NetReqQty - icc.AlreadyShippedQty) - icc.QtyShipped; if (icc.RemainBal < 1) { icc.RemainBal = 0; } } catch { icc.RemainBal = 0; } icc.BookSurplusQty = "Gross Req: " + dtTransaction.Rows[iCnt]["TOTAL"].ToString() + ",<br/> Stock total: " + dtTransaction.Rows[iCnt]["STOCK_TOTAL"].ToString() + ",<br/> Already Shiped: " + dtTransaction.Rows[iCnt]["ALREADYSHIPPED"].ToString() + ",<br/> Extra Book " + dtTransaction.Rows[iCnt]["SURPLUS_QTY"].ToString() + " " + (dtTransaction.Rows[iCnt]["SURPLUS_MODE"].ToString() == "PER" ? "%" : "Copies"); ObjlstInvCumCha.Add(icc); } if (dt != null && dt.Rows.Count > default(int)) { if (ObjlstInvCumCha != null && ObjlstInvCumCha.Count() > default(int)) { List <BinderDtlListByChallan> lst = new List <BinderDtlListByChallan>(); for (int i = 0; i < dt.Rows.Count; i++) { BinderDtlListByChallan obj = new BinderDtlListByChallan(); obj.BOOK_CODE = dt.Rows[i]["BOOK_CODE"].ToString(); obj.COMMON_BOOK_CODE = dt.Rows[i]["COMMON_BOOK_CODE"].ToString(); obj.TotalScannedCount = Convert.ToInt32(dt.Rows[i]["TotalScannedCount"].ToString()); obj.LOT = Convert.ToInt32(dt.Rows[i]["LOT"].ToString()); lst.Add(obj); } foreach (var item in ObjlstInvCumCha) { try { IEnumerable <BinderDtlListByChallan> obNew = lst.Where(s => s.BOOK_CODE == item.Book_Code); if (obNew != null && obNew.Count() > default(int)) { var lstOb = obNew.GroupBy(x => x.BOOK_CODE).Select(g => new { Key = g.Key, Value = g.Sum(s => s.TotalScannedCount), LOT = g.First().LOT, LOTDELIMITED = string.Join(",", g.Select(c => c.LOT.ToString()).ToArray()) }); var ob = lstOb.FirstOrDefault(); item.TotalLot = ob != null ? ob.LOT : item.TotalLot; item.TotalLotDelimited = ob != null ? (string.IsNullOrWhiteSpace(ob.LOTDELIMITED) ? item.TotalLot.ToString() : ob.LOTDELIMITED) : item.TotalLot.ToString(); item.QtyShipped = ob != null ? ob.Value : item.QtyShipped; item.RemainBal = (item.NetReqQty - item.AlreadyShippedQty) - item.QtyShipped; if (item.RemainBal < 1) { item.RemainBal = 0; } } //var ob = lst.Where(s => s.BOOK_CODE == item.Book_Code).FirstOrDefault(); //item.TotalLot = ob != null ? ob.LOT : item.TotalLot; ////item.TotalLotDelimited = ""; //item.QtyShipped = ob != null ? ob.TotalScannedCount : item.QtyShipped; //item.RemainBal = (item.NetReqQty - item.AlreadyShippedQty) - item.QtyShipped; //if (item.RemainBal < 1) // item.RemainBal = 0; } catch (Exception) { } } } } lst_invCumChal.TotalAmount = 0; lst_invCumChal.InvoiceCumChallanCollection = ObjlstInvCumCha.Where(o => o.NetReqQty > 0).ToList(); } dtTransaction.Dispose(); } catch (Exception ex) { objDbTrx.SaveSystemErrorLog(ex, Request.UserHostAddress); } if (isPartialViewRequest) { return(PartialView("~/Views/InvoiceCumChallanReqList/_ReqBookDtl.cshtml", lst_invCumChal)); } else { return(Json(lst_invCumChal, JsonRequestBehavior.AllowGet)); } }