public static RequestDetailObj_Render GetRequestDetails(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.DepotCode; obj.DepotId = ReqHeaderdetail.DepotId; obj.ReasonForReturn = ReqHeaderdetail.RequestType; obj.ReasonForReturn_Id = ReqHeaderdetail.RequestType_Id; obj.RequestTypeOption = ReqHDR.RequestTypeOption; obj.DocketNumber = ReqHDR.DocketNumber; obj.IsCommercialSettlement = ReqHDR.IsCommercialSettlement; obj.MaterialWillGoToDealer = ReqHDR.MaterialWillGoToDealer; obj.ParentRequest = ReqHDR.ParentRequest; obj.ReasonForCommercialSettlement = ReqHDR.ReasonForCommercialSettlement; obj.DetailsForMaterialGoToDealer = ReqHDR.DetailsForMaterialGoToDealer; obj.EPNo = ReqHDR.EPNo; obj.DealerNameForMail = ReqHeaderdetail.DealerName; obj.DealerCodeForMail = ReqHeaderdetail.DealerCode; obj.RequestDetail = new List <RequestDetailArray_Render>(); obj.DepotNameForMail = ReqHeaderdetail.DepotName; var ReqDetailList = context.tblRequestDtls.Where(x => x.RequestHeaderId == RequestId && x.IsActive == true).ToList(); double InvoiceAge = 0; decimal? TotalSRV_Value = 0; DateTime date = DateTime.Now; foreach (var pt in ReqDetailList) { var BarCodeDetails = context.TblBarCodeDetails.Where(x => x.SKU_Code == pt.SKUCode).FirstOrDefault(); var GetCCNumber = context.SP_GetCCNumber(pt.CCNo).FirstOrDefault(); var SalesReasonMasters = context.TblSalesReasonMasters.Where(x => x.SalesReason_Id == pt.SubReason).FirstOrDefault(); 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, Damaged = pt.DamagedQTY, DONo = pt.DONo, Acknowledge = pt.Acknowledge, Excess = pt.ExccessQTY, ReceivedQuantity = pt.ReceivedQTY, Short = pt.ShortQTY, SRVInvoiceNo = pt.SRVInvoiceNo, // Manufacturing_Date = BarCodeDetails != null ? BarCodeDetails.Manufacturing_Date : null, //Shelf_Life = context.spGetShelfLifeData(pt.SKUCode).FirstOrDefault().Shelf_Life.ToString(), Manufacturing_Date = pt.MFG_Date, Shelf_Life = pt.Shelf_Life, BatchNo = pt.BatchNo, ComplaintNumber = obj.ReasonForReturn_Id == 1 ? GetCCNumber != null ? GetCCNumber.ComplaintNumber : 0 : 0, SubReasonName = SalesReasonMasters != null ? SalesReasonMasters.SubReason : "", 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, selectedSKU = new SKUClass { SKUCode = pt.SKUCode, SKUName = pt.SKUName } }; obj.RequestDetail.Add(detailArray); TotalSRV_Value = TotalSRV_Value + detailArray.SRVValue; // getting invoice age from the oldest invoice date. if (pt.InvoiceDate != null) { double InvoiceDateAge = DateTime.Now.Subtract(pt.InvoiceDate.Value).Days / (365.25 / 12); //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 (ReqHeaderdetail.RequestType_Id != 3) { 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) { if (ReqHeaderdetail.RequestType_Id == 1) { if (TotalSRV_Value <= AppMatrixValue.ComplaintHandler && InvoiceAge <= AppMatrixPeriod.ComplaintHandler && FutureStatus_Id != 9) { obj.ShowApproveButton = true; } else if (FutureStatus_Id == 9) { obj.ShowApproveButton = true; } else { obj.ShowApproveButton = false; } } } else if (CurrentStatus_Id == 11) { if (ReqHeaderdetail.RequestType_Id == 2) { if (TotalSRV_Value < AppMatrixValue.LogisticsHead && InvoiceAge < AppMatrixPeriod.LogisticsHead) { obj.ShowApproveButton = true; } else if (FutureStatus_Id == 9) { obj.ShowApproveButton = true; } else { obj.ShowApproveButton = false; } } } else if (CurrentStatus_Id == 12 || CurrentStatus_Id == 13 || CurrentStatus_Id == 14 || FutureStatus_Id == 6 || FutureStatus_Id == 7 || FutureStatus_Id == 8) { obj.ShowApproveButton = true; } } else { if (FutureStatus_Id == 6) { if (TotalSRV_Value <= AppMatrixValue.RH && InvoiceAge <= AppMatrixPeriod.RH) { obj.ShowApproveButton = true; } else { obj.ShowApproveButton = false; } } else if (FutureStatus_Id == 7) { if (TotalSRV_Value <= AppMatrixValue.SegmentHead && InvoiceAge <= AppMatrixPeriod.SegmentHead) { obj.ShowApproveButton = true; } else { obj.ShowApproveButton = false; } } else if (FutureStatus_Id == 8) { if (TotalSRV_Value <= AppMatrixValue.VP && InvoiceAge <= AppMatrixPeriod.VP) { obj.ShowApproveButton = true; } else { obj.ShowApproveButton = false; } } else if (FutureStatus_Id == 9) { obj.ShowApproveButton = true; } //if (TotalSRV_Value <= AppMatrixValue.RH && InvoiceAge <= AppMatrixPeriod.RH) //{ // ApproverDAL.UpdateRequestStatus(isNew, Convert.ToInt32(RequestHeaderId), obj.EmployeeCode, UserDetail.Regional_Head, 1, 7, 1, 6, ""); //} //else if (TotalSRV_Value <= AppMatrixValue.SegmentHead && InvoiceAge <= AppMatrixPeriod.SegmentHead) //{ // ApproverDAL.UpdateRequestStatus(isNew, Convert.ToInt32(RequestHeaderId), obj.EmployeeCode, UserDetail.segmentHead, 1, 8, 1, 7, ""); //} //else if (TotalSRV_Value <= AppMatrixValue.VP && InvoiceAge <= AppMatrixPeriod.VP) //{ // ApproverDAL.UpdateRequestStatus(isNew, Convert.ToInt32(RequestHeaderId), obj.EmployeeCode, UserDetail.VPHead, 1, 9, 1, 8, ""); //} //else //{ // ApproverDAL.UpdateRequestStatus(isNew, Convert.ToInt32(RequestHeaderId), obj.EmployeeCode, UserDetail.President_Code, 1, 6, 1, 9, ""); //} } return(obj); } return(obj); } }
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); } }
public static string RecommendRequest(RecommendRequestObj data) { using (var context = new SalesReturndbEntities()) { string RequestProcessType = "recommended"; var RequestDetail = context.tblRequestDtls.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).ToList(); var approvalHeader = context.TblApproverHeaders.Where(x => x.Request_Id == data.Request_Id && x.IsActive == true).FirstOrDefault(); var ReqHdrDetail = context.SP_GetRequestDetail(data.Request_Id).FirstOrDefault(); var RequestHdr = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault(); var UserDetail = context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault(); var Reqfuturestatus = context.TblFutureStatus.Where(x => x.IsActive == true && x.Request_ID == ReqHdrDetail.RequestHeaderId).OrderByDescending(y => y.FutStatus_ID).FirstOrDefault(); string AssignedTo = ""; string Message = ""; var CurrStatus = 0; var FutStatus = 0; var Active_role = 0; var Requested_role = 0; decimal? TotalSRV_Value = 0; DateTime date = DateTime.Now; double InvoiceAge = 0; //int FutureStatus_Id = 0; foreach (var pt in RequestDetail) { TotalSRV_Value = TotalSRV_Value + pt.SRVValue; // getting invoice age from the oldest invoice date. double InvoiceDateAge = DateTime.Now.Subtract(pt.InvoiceDate.Value).Days / (365.25 / 12); if (InvoiceAge <= InvoiceDateAge) { InvoiceAge = InvoiceDateAge; } } //var ApprovalMatrixData = context.TblApprovalMatrices.Where(x => x.RequestType == data.RequestType_Id && x.Country.Equals(data.Country) && x.BUType.Equals(UserDetail.SBU_Name) && x.Division.Equals(UserDetail.Dept_name) && x.IsActive == true).FirstOrDefault(); var FlowMatrixValue = context.TblFlowMatrices.Where(x => x.RequestType == data.RequestType_Id && x.Options.Equals("Value") && x.IsActive == true).FirstOrDefault(); var FlowMatrixPeriod = context.TblFlowMatrices.Where(x => x.RequestType == data.RequestType_Id && x.Options.Equals("Period") && x.IsActive == true).FirstOrDefault(); var EmployeeMatrixData = context.TblEmployeeMasters.Where(x => x.IsActive == true && x.DepotName == ReqHdrDetail.DepotName).FirstOrDefault(); if (FlowMatrixValue != null && FlowMatrixPeriod != null && EmployeeMatrixData != null) { if (approvalHeader.Status_Id == 1) { if (data.RequestType_Id == 1) { if (EmployeeMatrixData.ComplaintManager != null || EmployeeMatrixData.ComplaintManager != "") { if (TotalSRV_Value <= FlowMatrixValue.ComplaintHandler && InvoiceAge <= FlowMatrixPeriod.ComplaintHandler) { AssignedTo = EmployeeMatrixData.ComplaintManager; } else { AssignedTo = UserDetail.President_Code; data.Requested_Role = 6; data.FutureStatus_Id = 9; } if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); if (TotalSRV_Value <= FlowMatrixValue.ComplaintHandler && InvoiceAge <= FlowMatrixPeriod.ComplaintHandler) { //Recommeneded complaint manager. CurrStatus = 12; FutStatus = 9; Active_role = 3; Requested_role = 6; } else { //Approve complaint manager. CurrStatus = 16; FutStatus = 0; Active_role = 3; Requested_role = 0; } data.Active_Role = Active_role; data.Requested_Role = Requested_role; data.CurrentStatus_Id = CurrStatus; data.FutureStatus_Id = FutStatus; } } else { return("Error : Complaint Manager is not defined in Approval Matrix"); } } else if (data.RequestType_Id == 2) { if (EmployeeMatrixData.ISC != null || EmployeeMatrixData.ISC != "") { if (TotalSRV_Value <= FlowMatrixValue.LogisticsHead && InvoiceAge <= FlowMatrixPeriod.LogisticsHead) { AssignedTo = EmployeeMatrixData.ISC; } else { AssignedTo = UserDetail.President_Code; data.Requested_Role = 6; data.FutureStatus_Id = 9; } //AssignedTo = EmployeeMatrixData.LogisticsHead; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); if (TotalSRV_Value <= FlowMatrixValue.LogisticsHead && InvoiceAge <= FlowMatrixPeriod.LogisticsHead) { //Recommeneded Logictic Head/ VP. CurrStatus = 13; FutStatus = 9; Active_role = 5; Requested_role = 6; } else { //Approve Logictic Head/ VP. CurrStatus = 16; FutStatus = 0; Active_role = 5; Requested_role = 0; } data.Active_Role = Active_role; data.Requested_Role = Requested_role; data.CurrentStatus_Id = CurrStatus; data.FutureStatus_Id = FutStatus; } } else { return("Error : Logistic Head is not set in Approval Matrix"); } } else if (data.RequestType_Id == 3) { var ReqHdr = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault(); if (ReqHdr.RequestTypeOption == "D") { //In D type request we will refer VP/SH/President of RM not of requester var RM_Trail = context.SP_LFGDetails(data.EmployeeCode).FirstOrDefault(); if (TotalSRV_Value <= FlowMatrixValue.VP && InvoiceAge <= FlowMatrixPeriod.VP) { if (RM_Trail.VPHead != "NA" && RM_Trail.VPHead != "" && RM_Trail.VPHead != null) { AssignedTo = UserDetail.VPHead; data.FutureStatus_Id = 8; //Pending Sales Director / VP Head; data.Requested_Role = 9; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 9; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : Sales Director/VP Head is not Defined."); } } else { if (RM_Trail.President_Code != "NA" && RM_Trail.President_Code != "" && RM_Trail.President_Code != null) { AssignedTo = UserDetail.President_Code; data.FutureStatus_Id = 9;//Pending President data.Requested_Role = 6; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 6; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : President code is not in LFG."); } } } else { if (TotalSRV_Value <= FlowMatrixValue.SegmentHead && InvoiceAge <= FlowMatrixPeriod.SegmentHead) { var DealerDtl = context.sp_GetDealerDtlBy_DealerRepositoryId(ReqHdr.DealerId).FirstOrDefault(); // if (DealerDtl!=null) if (UserDetail.segmentHead != "NA" && UserDetail.segmentHead != "" && UserDetail.segmentHead != null) { //AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().EMP_CODE; if (UserDetail.segmentHead != "NA" && UserDetail.segmentHead != "" && UserDetail.segmentHead != null) { AssignedTo = UserDetail.segmentHead; } else { return("Error : Segment Head is not in LFG."); if (DealerDtl != null) { AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().EMP_CODE; } } data.FutureStatus_Id = 7; //Pending Segment Head; data.Requested_Role = 8; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 8; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : Segment head is not defined in PMS."); } } else if (TotalSRV_Value <= FlowMatrixValue.VP && InvoiceAge <= FlowMatrixPeriod.VP) { var DealerDtl = context.sp_GetDealerDtlBy_DealerRepositoryId(ReqHdr.DealerId).FirstOrDefault(); //if (DealerDtl!=null) if (UserDetail.VPHead != "NA" && UserDetail.VPHead != "" && UserDetail.VPHead != null) { // AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().VPHead; if (UserDetail.VPHead != "NA" && UserDetail.VPHead != "" && UserDetail.VPHead != null) { AssignedTo = UserDetail.VPHead; } else { return("Error : VP Head is not in LFG."); if (DealerDtl != null) { AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().VPHead; } } data.FutureStatus_Id = 8; //Pending Sales Director / VP Head; data.Requested_Role = 9; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 9; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : Sales Director/VP Head is not Defined."); } } else { var DealerDtl = context.sp_GetDealerDtlBy_DealerRepositoryId(ReqHdr.DealerId).FirstOrDefault(); //if (DealerDtl!=null) if (UserDetail.President_Code != "NA" && UserDetail.President_Code != "" && UserDetail.President_Code != null) { // AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().President_Code; if (UserDetail.President_Code != "NA" && UserDetail.President_Code != "" && UserDetail.President_Code != null) { AssignedTo = UserDetail.President_Code; } else { return("Error : President code is not in LFG."); if (DealerDtl != null) { AssignedTo = context.SP_LFGDetailsBasedOnName(DealerDtl.Segment).FirstOrDefault().President_Code; } } data.FutureStatus_Id = 9;//Pending President data.Requested_Role = 6; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 6; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : President code is not in LFG."); } } } } } else if (approvalHeader.Status_Id == 10 || approvalHeader.Status_Id == 11) { if (UserDetail.President_Code.ToUpper().Trim() != "NA" && UserDetail.President_Code.Trim() != "" && UserDetail.President_Code != null) { AssignedTo = UserDetail.President_Code;//context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault().President_Code; if (data.EmployeeCode.Equals(AssignedTo)) { //auto approval code here. ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); data.Active_Role = 6; data.Requested_Role = 0; data.CurrentStatus_Id = 16; data.FutureStatus_Id = 0; } } else { return("Error : President code is not in LFG."); } } ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignedTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); SendMail(approvalHeader, data, RequestProcessType, AssignedTo); Message = "Success : " + RequestHdr.RequestTypeOption + "-" + data.Request_Id + " Request has been Updated."; } else { Message = "Error : Approval matrix is not Defined. Please contact admin."; } return(Message); } }