public static RequestDetailObj_Render GetRequestDetailsforNextStage(int RequestId, int CurrentStatus_Id, int FutureStatus_Id) { using (var context = new SalesReturndbEntities()) { RequestDetailObj_Render obj = new RequestDetailObj_Render(); var ReqHeaderdetail = context.SP_GetRequestDetail(RequestId).FirstOrDefault(); var UserDetail = context.SP_LFGDetails(ReqHeaderdetail.CreatedBy).FirstOrDefault(); var AppMatrixValue = context.TblFlowMatrices.Where(x => x.RequestType == (ReqHeaderdetail.RequestType_Id) && x.IsActive == true && x.Options == "Value").FirstOrDefault(); var AppMatrixPeriod = context.TblFlowMatrices.Where(x => x.RequestType == (ReqHeaderdetail.RequestType_Id) && x.IsActive == true && x.Options == "Period").FirstOrDefault(); if (ReqHeaderdetail != null) { var ReqHDR = context.TblRequestHeaders.Where(x => x.RequestHeaderId == RequestId && x.IsActive == true).FirstOrDefault(); obj.RequestHeader_Id = ReqHeaderdetail.RequestHeaderId; obj.DealerName = ReqHeaderdetail.DealerName + ":" + ReqHeaderdetail.DealerCode; obj.DealerId = ReqHeaderdetail.DealerId; obj.DepotName = ReqHeaderdetail.DepotName + " : " + ReqHeaderdetail.DealerCode; obj.DepotId = ReqHeaderdetail.DepotId; obj.ReasonForReturn = ReqHeaderdetail.RequestType; obj.ReasonForReturn_Id = ReqHeaderdetail.RequestType_Id; obj.RequestTypeOption = ReqHDR.RequestTypeOption; obj.RequestDetail = new List <RequestDetailArray_Render>(); var ReqDetailList = context.tblRequestDtls.Where(x => x.RequestHeaderId == RequestId && x.IsActive == true).ToList(); int InvoiceAge = 0; decimal? TotalSRV_Value = 0; DateTime date = DateTime.Now; foreach (var pt in ReqDetailList) { if (pt.ReleaseByCM == false) { continue; } RequestDetailArray_Render detailArray = new RequestDetailArray_Render() { Detail_Id = pt.Id, InvoiceDate = pt.InvoiceDate, InvoiceNo = pt.InvoiceNumber, InvoiceQuantity = pt.InvoiceQuantity, PackSize = pt.PackSize, ProvideGST_Yes = pt.ReadyToProvideGST, ProvideGST_No = (pt.ReadyToProvideGST != null && pt.ReadyToProvideGST.Value == true) ? false : true, Remarks = pt.Remarks, SRVQuantity = pt.SRVQuantity, SRVValue = pt.SRVValue, Unit = pt.Unit, Volume = (pt.SRVQuantity * pt.PackSize), SKUCode = pt.SKUCode, SKUName = pt.SKUName, Acknowledge = pt.Acknowledge, Damaged = pt.DamagedQTY, Excess = pt.ExccessQTY, ReceivedQuantity = pt.ReceivedQTY, SAPsubReasonID = pt.ReasonforSAP, Short = pt.ShortQTY, Manufacturing_Date = context.TblBarCodeDetails.Where(x => x.SKU_Code == pt.SKUCode).Select(y => y.Manufacturing_Date).FirstOrDefault(), Shelf_Life = context.spGetShelfLifeData(pt.SKUCode).FirstOrDefault().Shelf_Life.ToString(), BatchNo = pt.BatchNo, ComplaintNumber = obj.ReasonForReturn_Id == 1 ? context.SP_GetCCNumber(pt.CCNo).FirstOrDefault().ComplaintNumber : 0, SubReasonName = context.TblSalesReasonMasters.Where(x => x.SalesReason_Id == pt.SubReason).Select(y => y.SubReason).FirstOrDefault(), SubReason = pt.SubReason, UploadedInvoice = (pt.ReadyToProvideGST != null && pt.ReadyToProvideGST.Value == true) ? context.TblUploadedInvoices.Where(x => x.RequestDetail_Id == pt.Id && x.IsActive == true).FirstOrDefault().ImageUploaded : "", UploadedInvoice_Id = (pt.ReadyToProvideGST != null && pt.ReadyToProvideGST.Value == true) ? context.TblUploadedInvoices.Where(x => x.RequestDetail_Id == pt.Id && x.IsActive == true).FirstOrDefault().Id : 0, DONo = pt.DONo, SRVInvoiceNo = pt.SRVInvoiceNo, ReleaseByCM = pt.ReleaseByCM, ReleaseByCM_Date = pt.ReleaseByCM_Date }; obj.RequestDetail.Add(detailArray); TotalSRV_Value = TotalSRV_Value + detailArray.SRVValue; // getting invoice age from the oldest invoice date. if (pt.InvoiceDate != null) { int InvoiceDateAge = ((date.Year - pt.InvoiceDate.Value.Year) * 12) + date.Month - pt.InvoiceDate.Value.Month; if (InvoiceAge <= InvoiceDateAge) { InvoiceAge = InvoiceDateAge; } } } // if request is pending to user. if (FutureStatus_Id == 17) { foreach (var item in obj.RequestDetail) { if (ReqHeaderdetail.RequestType_Id == 1) { var ccDetail = context.SP_GetCCNumber(item.ComplaintNumber).FirstOrDefault(); item.selectedComplaint = new ComplaintDetail_Render(); item.selectedComplaint.Complaint_ID = ccDetail.Complaint_ID; item.selectedComplaint.ComplaintDesc = ccDetail.ComplaintDesc; item.selectedComplaint.ComplaintNumber = ccDetail.ComplaintNumber; } var SKUDetail = context.SP_GetSKUCode(item.SKUCode).FirstOrDefault(); if (SKUDetail != null) { //item.selectedSKU = new SKUClass(); item.selectedSKU = new SKUClass(); item.selectedSKU.SKUCode = SKUDetail.SKUCode; item.selectedSKU.SKUName = SKUDetail.SKUName; item.selectedSKU.SKUDescription = SKUDetail.SKUDescription; } } } if (CurrentStatus_Id == 10 || CurrentStatus_Id == 11) { //if (TotalSRV_Value < AppMatrixValue.ComplaintHandler && InvoiceAge < AppMatrix.InvoiceAge) if (TotalSRV_Value < AppMatrixValue.ComplaintHandler) { obj.ShowApproveButton = false; } else { obj.ShowApproveButton = true; } } else if (CurrentStatus_Id == 12 || CurrentStatus_Id == 13 || CurrentStatus_Id == 14 || FutureStatus_Id == 6 || FutureStatus_Id == 7 || FutureStatus_Id == 8) { obj.ShowApproveButton = true; } return(obj); } return(obj); } }