コード例 #1
0
        public static MailAddressCollection GetCC(RecommendRequestObj obj)
        {
            try
            {
                using (var context = new SalesReturndbEntities())
                {
                    MailAddressCollection   ccEmail = new MailAddressCollection();
                    RequestDetailObj_Render data1   = CommonDAL.GetRequestDetails(obj.Request_Id, obj.CurrentStatus_Id, obj.FutureStatus_Id);
                    var RegionalHead = context.SP_LFGDetails(data1.EmployeeCode).FirstOrDefault();

                    if (RegionalHead != null)
                    {
                        if (!(RegionalHead.Regional_Head.ToUpper().Trim().Equals("NA") || RegionalHead.Regional_Head.Trim().Equals(string.Empty)))
                        {
                            var RegionalHeadData = context.SP_LFGDetails(RegionalHead.Regional_Head).FirstOrDefault();
                            ccEmail.Add(RegionalHeadData.email_id);
                        }
                        if (!(RegionalHead.segmentHead.ToUpper().Trim().Equals("NA") || RegionalHead.segmentHead.Trim().Equals(string.Empty)))
                        {
                            var SegmentHeadData = context.SP_LFGDetails(RegionalHead.segmentHead).FirstOrDefault();
                            ccEmail.Add(SegmentHeadData.email_id);
                        }
                        ccEmail.Add(RegionalHead.email_id);//Email Id of Requestor
                    }

                    var DepotMaster      = context.SP_GetDepotList().Where(x => x.DepotId == data1.DepotId).FirstOrDefault();
                    var AssintoEmp       = context.TblEmployeeMasters.Where(x => x.IsActive == true && x.DepotName == DepotMaster.DepotName).FirstOrDefault();
                    var ComplaintHandler = context.SP_LFGDetails(AssintoEmp.ComplaintHandler).FirstOrDefault();
                    var CompalintManager = context.SP_LFGDetails(AssintoEmp.ComplaintManager).FirstOrDefault();
                    ccEmail.Add(ComplaintHandler.email_id);
                    ccEmail.Add(CompalintManager.email_id);
                    var LogistickHead = context.SP_LFGDetails(AssintoEmp.LogisticsHead).FirstOrDefault();
                    ccEmail.Add(LogistickHead.email_id);
                    if (RegionalHead != null)
                    {
                        if (!(RegionalHead.VPHead.ToUpper().Trim().Equals("NA") || RegionalHead.VPHead.Trim().Equals(string.Empty)))
                        {
                            var vphead = context.sp_GetuserDetailsFromLFG(RegionalHead.VPHead).FirstOrDefault();
                            ccEmail.Add(vphead.email_id);
                        }
                        if (!(RegionalHead.President_Code.ToUpper().Trim().Equals("NA") || RegionalHead.President_Code.Trim().Equals(string.Empty)))
                        {
                            var President_Code = context.sp_GetuserDetailsFromLFG(RegionalHead.President_Code).FirstOrDefault();
                            ccEmail.Add(President_Code.email_id);
                        }
                    }

                    var depot = context.SP_LFGDetails(AssintoEmp.Depotcode).FirstOrDefault();
                    ccEmail.Add(depot.email_id);
                    var cso = context.SP_LFGDetails(AssintoEmp.CSO).FirstOrDefault();
                    ccEmail.Add(cso.email_id);
                    return(ccEmail);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public static string ApproveRequest(RecommendRequestObj data)
        {
            try
            {
                using (var context = new SalesReturndbEntities())
                {
                    string RequestType            = "approve";
                    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    ReqHdr                 = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault();
                    RequestDetailObj_Render data1 = CommonDAL.GetRequestDetails(data.Request_Id, data.CurrentStatus_Id, data.FutureStatus_Id);
                    var    UserDetail             = context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault();
                    var    DepotDTl               = context.sp_GetDealerDtlBy_DealerRepositoryId(ReqHdr.DealerId).FirstOrDefault();
                    string assignTo               = string.Empty;

                    var DepotPersonDtl = context.TblEmployeeMasters.Where(x => x.DepotName == DepotDTl.Depot).FirstOrDefault();
                    if (data.FutureStatus_Id == 10019)
                    {
                        assignTo = DepotPersonDtl.Depotcode;
                    }
                    ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, assignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks);
                    SendMail(approvalHeader, data, RequestType, assignTo);
                    return("Success : " + ReqHdr.RequestTypeOption + "-" + data.Request_Id + " Requested has been approved successfully.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public static List <PendingRequestModel> getPendingRequest(string EmployeeCode)
        {
            using (var context = new SalesReturndbEntities())
            {
                List <PendingRequestModel> dataList = null;
                var PendingRequestList = context.SP_GetPendingRequest(EmployeeCode).ToList();
                if (PendingRequestList != null)
                {
                    dataList = PendingRequestList.Select(x => new PendingRequestModel()
                    {
                        BatchNo            = x.BatchNo,
                        DealerAddress      = x.DealerAddress,
                        DealerCode         = x.DealerCode,
                        DealerName         = x.DealerName,
                        DepotName          = x.DepotName,
                        DepotAddress       = x.DepotAddress,
                        DepotCode          = x.DepotCode,
                        FutureStatus       = x.FutureStatus,
                        RequestHeaderId    = x.RequestHeaderId,
                        FutureStatus_Id    = x.FutureStatus_Id,
                        CurrentStatus_Id   = x.CurrentStatus_Id,
                        SKUCode            = x.SKUCode,
                        SKUName            = x.SKUName,
                        CreatedBy_EMP_CODE = x.CreatedBy,
                        CreatedBy          = context.SP_LFGDetails(x.CreatedBy).FirstOrDefault().Emp_First_name,
                        CreatedDate        = x.CreatedDate,

                        TotalSRV          = context.tblRequestDtls.Where(o => o.RequestHeaderId == x.RequestHeaderId && o.IsActive == true).Sum(p => p.SRVValue).Value,
                        RequestTypeOption = x.SKUCode,// for access data behalf on skucode
                    }).ToList();
                    return(dataList);
                }
                return(dataList);
            }
        }
コード例 #4
0
        public static List <PendingRequestModel> GetOpenRequest(string empCode)
        {
            List <PendingRequestModel> List = new List <PendingRequestModel>();

            using (var context = new SalesReturndbEntities())
            {
                var data = context.SP_GetOpenRequest(empCode).ToList();
                if (data.Count != 0)
                {
                    List = data.Select(x => new PendingRequestModel()
                    {
                        BatchNo            = x.BatchNo,
                        DealerAddress      = x.DealerAddress,
                        DealerCode         = x.DealerCode,
                        DealerName         = x.DealerName,
                        DepotName          = x.DealerName,
                        DepotAddress       = x.DepotAddress,
                        DepotCode          = x.DepotCode,
                        RequestHeaderId    = x.RequestHeaderId,
                        CurrentStatus      = x.CurrentStatus,
                        CurrentStatus_Id   = x.CurrentStatus_Id,
                        SKUCode            = x.SKUCode,
                        SKUName            = x.SKUName,
                        CreatedBy_EMP_CODE = x.CreatedBy,
                        CreatedBy          = context.SP_LFGDetails(x.CreatedBy).FirstOrDefault().Emp_First_name,
                        CreatedDate        = x.CreatedDate,

                        TotalSRV = context.tblRequestDtls.Where(o => o.RequestHeaderId == x.RequestHeaderId && o.IsActive == true).Sum(p => p.SRVValue),
                    }).ToList();
                }
                return(List);
            }
        }
コード例 #5
0
        public static string CloseRequest(CloseRequestObjForStg_4 data)
        {
            using (var context = new SalesReturndbEntities())
            {
                string AssignTo       = string.Empty;
                string RetMsg         = string.Empty;
                var    RequestDetail  = context.tblRequestDtls.Where(x => x.RequestHeaderId == data.Request_Id).ToList();
                var    approvalHeader = context.TblApproverHeaders.Where(x => x.Request_Id == data.Request_Id).FirstOrDefault();
                var    ReqHdr         = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault();
                var    UserDetail     = context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault();
                var    DlrDtl         = context.sp_GetDealerDtlBy_DealerRepositoryId(data.Request.DealerId).FirstOrDefault();
                if (data.FutureStatus_Id == 10027 || data.CurrentStatus_Id == 10028 || data.CurrentStatus_Id == 10029)
                {
                    var EmpMaster = context.TblEmployeeMasters.Where(x => x.DepotName == DlrDtl.Depot && x.IsActive == true).FirstOrDefault();
                    AssignTo = data.FutureStatus_Id == 10027 ? EmpMaster.Depotcode : "";
                    if (data.Request.IsCommercialSettlement == true)
                    {
                        var EpCheck = context.sp_CheckEPNumber(data.Request.EPNo).FirstOrDefault();
                        if (EpCheck == null)
                        {
                            return("Error: EP Number does not exists");
                        }
                    }
                    ReqHdr.IsCommercialSettlement        = data.Request.IsCommercialSettlement;
                    ReqHdr.MaterialWillGoToDealer        = data.Request.IsCommercialSettlement == true ? false : true;
                    ReqHdr.ReasonForCommercialSettlement = data.Request.IsCommercialSettlement == true ? data.Request.ReasonForCommercialSettlement : "";
                    ReqHdr.DetailsForMaterialGoToDealer  = data.Request.IsCommercialSettlement == false ? data.Request.DetailsForMaterialGoToDealer : "";
                    ReqHdr.EPNo         = data.Request.IsCommercialSettlement == true ? data.Request.EPNo : "";
                    ReqHdr.ModifiedBy   = data.EmployeeCode;
                    ReqHdr.ModifiedDate = DateTime.Now;

                    context.Entry(ReqHdr).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();

                    RetMsg = data.FutureStatus_Id == 10027 ? "Request has been forwarded to Depot!" : "Request has been closed successfully!";
                }
                else if (data.CurrentStatus_Id == 10030)
                {
                    ReqHdr.DocketNumber         = data.Request.DocketNumber;
                    ReqHdr.DocketDate           = data.Request.DocketDate;
                    context.Entry(ReqHdr).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();

                    RetMsg = "Request has been closed successfully!";
                }
                else
                {
                    RetMsg = "Request has been closed successfully!";
                }

                ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks);

                return("Success : " + ReqHdr.RequestTypeOption + data.Request_Id + " " + RetMsg);
            }
        }
コード例 #6
0
        public static string RejectRequest(RecommendRequestObj data)
        {
            using (var context = new SalesReturndbEntities())
            {
                string RequestProcessType = "reject";
                string AssignTo           = string.Empty;
                var    RequestDetail      = context.tblRequestDtls.Where(x => x.RequestHeaderId == data.Request_Id).ToList();
                var    approvalHeader     = context.TblApproverHeaders.Where(x => x.Request_Id == data.Request_Id).FirstOrDefault();
                var    ReqHdr             = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault();
                var    IfDepotPerson      = context.TblEmployeeMasters.Where(x => x.Depotcode == ReqHdr.EmployeeCode && x.IsActive == true).FirstOrDefault();
                var    UserDetail         = context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault();
                var    Reqfuturestatus    = context.TblFutureStatus.Where(x => x.IsActive == true && x.Request_ID == ReqHdr.RequestHeaderId).OrderByDescending(y => y.FutStatus_ID).FirstOrDefault();
                if (data.FutureStatus_Id == 10026 && IfDepotPerson == null)
                {
                    if (UserDetail.Regional_Head.Trim().Equals("NA") || UserDetail.Regional_Head.Trim().Equals("N/A"))
                    {
                        return("Error: Approval Matrix not defined!!");
                    }
                    else
                    {
                        AssignTo = UserDetail.Regional_Head;
                        ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks);
                    }
                }
                else if (data.FutureStatus_Id == 10026 && IfDepotPerson != null)
                {
                    var  DealerDtl = context.sp_GetDealerDtlBy_DealerRepositoryId(ReqHdr.DealerId).FirstOrDefault();
                    bool IsRMExist = DealerDtl != null ? (DealerDtl.RMCode.Equals(string.Empty) ? false : (DealerDtl.RMCode.Contains("NA") ? false : (DealerDtl.RMCode == null ? false : true))) : false;
                    //if (IsRMExist) {
                    if (UserDetail.Regional_Head != "NA" && UserDetail.Regional_Head != null && UserDetail.Regional_Head != "")
                    {
                        // AssignTo = DealerDtl.RMCode;
                        AssignTo = UserDetail.Regional_Head;

                        ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks);
                    }
                    else
                    {
                        return("Error: Approval Matrix not defined!!");
                    }
                }
                else
                {
                    ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks);
                }
                SendMail(approvalHeader, data, RequestProcessType, ReqHdr.EmployeeCode);
                return("Success : " + ReqHdr.RequestTypeOption + data.Request_Id + " Requested has been rejected successfully.");
            }
        }
コード例 #7
0
 public static bool CheckIfEmployeeExist(string EmployeeCode)
 {
     using (var context = new SalesReturndbEntities())
     {
         var check = context.SP_LFGDetails(EmployeeCode).FirstOrDefault();
         if (check != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
コード例 #8
0
        public static LoginModel GetEmployeeDetails(string id, string conn)
        {
            LoginModel user = null;

            using (var DbContext = new SalesReturndbEntities())
            {
                var source        = DbContext.SP_LFGDetails(id).FirstOrDefault();
                var IfDepotPerson = DbContext.sp_CheckIfDepotPerson(id).FirstOrDefault();
                if (source != null)
                {
                    user = new LoginModel
                    {
                        EMP_CODE       = source.EMP_CODE.ToString(),
                        Emp_First_name = source.Emp_First_name.ToString(),
                        Desg_Desc      = source.Desg_Desc,
                        Dept_name      = source.Dept_name,
                        IsDepotPerson  = IfDepotPerson != null?true:false,
                        DepotName      = IfDepotPerson?.DepotName,
                        DepotCode      = IfDepotPerson?.DepotCode,
                        Seg_Name       = source.Seg_Name,
                        DepotId        = IfDepotPerson != null? IfDepotPerson.DepotId:0,
                        email_id       = source.email_id,
                        Mobile_no      = source.Mobile_no,
                        SBU_Name       = source.SBU_Name,
                        Zone           = source.Zone,
                        RegionHead     = source.Regional_Head,
                        SegmentHead    = source.Country_Head,
                        Oth_key        = id,
                        Country        = source.Country
                    };

                    var checkAdmin = DbContext.TblAdminMasters.Where(x => x.EmployeeCode.Equals(id) && x.IsActive == true).FirstOrDefault();

                    if (id.Equals("0") || checkAdmin != null)
                    {
                        user.RoleName = "Admin";
                    }
                }
            }
            return(user);
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        public static void SendMail(TblApproverHeader ApproverHdr, RecommendRequestObj data, string ProcessType, string to)
        {
            try
            {
                using (var context = new SalesReturndbEntities())
                {
                    TblMailTemplate EmailTemplate = new TblMailTemplate();
                    string          subject       = string.Empty;

                    if (ProcessType == "reject")
                    {
                        if (data.Active_Role == 2)//ch
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 5).FirstOrDefault();
                        }
                        else if (data.Active_Role == 3)//cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 8).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4)//lm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 11).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5)//ISC/Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 14).FirstOrDefault();
                        }
                        else if (data.Active_Role == 8)//sh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 21).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)//Regionl Head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 18).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5)//Vp Head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 24).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6)//President
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 27).FirstOrDefault();
                        }
                        //   subject = EmailTemplate.Subject.Replace("<RequestNo.>", "S" + "-" + data.Request_Id);
                    }
                    if (ProcessType == "reconsider")
                    {
                        if (data.Active_Role == 2) //ch
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 6).FirstOrDefault();
                        }
                        else if (data.Active_Role == 3) //cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 9).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4) //lm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 12).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5) //isc Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 15).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7) //regional head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 19).FirstOrDefault();
                        }
                        else if (data.Active_Role == 8) //Segment head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 22).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5) //isc Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 25).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6) //presdient
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 28).FirstOrDefault();
                        }
                        // subject = EmailTemplate.Subject.Replace("<RequestNo.>", "S" + "-" + data.Request_Id);
                    }

                    if (ProcessType == "recommended")
                    {
                        if (data.Active_Role == 2)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 4).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 10).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 17).FirstOrDefault();
                        }

                        //subject = EmailTemplate.Subject.Replace("<RequestNo.>", data.Request_Id.ToString());
                    }
                    if (ProcessType == "approve")
                    {
                        if (data.Active_Role == 5)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 13).FirstOrDefault();
                        }

                        else if (data.Active_Role == 3)//cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 7).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)//rh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 26).FirstOrDefault();
                        }
                        else if (data.Active_Role == 9)//sh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 20).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6) //president
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 26).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7) //RegionalHead
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 16).FirstOrDefault();
                        }
                        // subject = EmailTemplate.Subject.Replace("<RequestNo.>", data.Request_Id.ToString());
                    }
                    subject = EmailTemplate.Subject;
                    subject = GetSubject(subject, data);
                    string Body = GetHtml(EmailTemplate.MailBody, data);
                    //var CCMails = GetCC(data);
                    MailAddressCollection CCMails = new MailAddressCollection();
                    //CCMails.Add("*****@*****.**");
                    CCMails.Add("*****@*****.**");
                    int RequestType = data.RequestType_Id;
                    var UserDetail  = context.SP_LFGDetails(to).FirstOrDefault();
                    var FromEmail   = context.SP_LFGDetails(data.EmployeeCode).FirstOrDefault();
                    Body = Body.Replace("Requestor Name", FromEmail.Emp_First_name);
                    MailAddressCollection toMail   = new MailAddressCollection();
                    MailAddressCollection fromMail = new MailAddressCollection();
                    subject = subject.Replace("<EmployeeName>", FromEmail.Emp_First_name);
                    // toMail.Add(UserDetail.email_id);
                    // toMail.Add("*****@*****.**");
                    toMail.Add("*****@*****.**");

                    fromMail.Add(FromEmail.email_id);
                    Email.sendEmail(subject, "*****@*****.**", toMail, CCMails, Body);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #12
0
        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);
            }
        }