public SalaryProcessDetailsVM SaveSalaryProcessD(SalaryProcessDetailsVM salary)
 {
     if (!salary.EditFlag)
     {
         salary.PRSP001_Code = _CodeRep.GetCode(salary.CmpyCode, "SalaryProcess");
     }
     return(_salaryrepo.SaveSalaryProcessD(salary));
 }
        public ActionResult SaveSalaryProcess(SalaryProcessDetailsVM salarym)
        {
            List <SessionListnew> list = Session["SesDet"] as List <SessionListnew>;

            if (list == null)
            {
                return(Redirect("Login/InLogin"));
            }
            else
            {
                salarym.CmpyCode = list[0].CmpyCode;
                salarym.UserName = list[0].user_name;
                return(Json(_SalService.SaveSalaryProcessD(salarym), JsonRequestBehavior.AllowGet));
            }
        }
        public SalaryProcessDetailsVM  GetSalaryProcessEdit(string CmpyCode, string salaryCode)
        {
            ds = _EzBusinessHelper.ExecuteDataSet("select * from PRSP001 where CmpyCode='" + CmpyCode + "' and PRSP001_CODE='" + salaryCode + "' and Flag=0");
            dt = ds.Tables[0];
            SalaryProcessDetailsVM drc = new SalaryProcessDetailsVM();

            foreach (DataRow dr in dt.Rows)
            {
                drc.CmpyCode      = dr["CmpyCode"].ToString();
                drc.PRSP001_Code  = dr["PRSP001_Code"].ToString();
                drc.Country       = dr["Country"].ToString();
                drc.DivisionCode  = dr["Division"].ToString();
                drc.VisaLocation1 = dr["VisaLocation"].ToString();
                drc.year          = Convert.ToInt32(dr["Tyear"].ToString());
                drc.Month         = Convert.ToInt32(dr["Tmonth"].ToString());
                drc.Process_Date  = Convert.ToDateTime(dr["Process_Date"].ToString());
            }
            return(drc);
        }
        public ActionResult GetCalculatedSalaryDetails(SalaryProcessDetailsVM slryVM)
        {
            JsonResult result = new JsonResult();

            try
            {
                List <SessionListnew> list = Session["SesDet"] as List <SessionListnew>;
                if (list == null)
                {
                    return(Redirect("Login/InLogin"));
                }
                else
                {
                    // Initialization.
                    string search   = Request.Form.GetValues("search[value]")[0];
                    string draw     = Request.Form.GetValues("draw")[0];
                    string order    = Request.Form.GetValues("order[0][column]")[0];
                    string orderDir = Request.Form.GetValues("order[0][dir]")[0];
                    int    startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
                    int    pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);

                    if (pageSize == -1)
                    {
                        draw = "2";
                    }
                    List <SalaryProcessDetailsListItem> data = _SalService.GetSalaryProcessGrid(list[0].CmpyCode, slryVM.Process_Date, slryVM.DivisionCode, slryVM.Deptcode, slryVM.VisaLocation1);
                    // Total record count.
                    int totalRecords = 0;
                    if (data != null)
                    {
                        totalRecords = data.Count;
                    }
                    else
                    {
                        totalRecords = 0;
                    }
                    // Verification.
                    if (!string.IsNullOrEmpty(search) &&
                        !string.IsNullOrWhiteSpace(search))
                    {
                        // Apply search
                        data = data.Where(p => p.srno.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Empcode.ToLower().Contains(search.ToLower()) ||
                                          p.Empname.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.country.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Tmonth.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Tyear.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.cmpycode.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.ProfCode.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.DepCode.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.ComnPrjcode.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Division.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.VisaLocation.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.WorkLocation.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Total_Days.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.Worked_Days.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.VisaLocation.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.loan_amt.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.adn_amount.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.nothrs.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.extraOThrs.ToString().ToLower().Contains(search.ToLower()) ||
                                          p.hothrs.ToString().ToLower().Contains(search.ToLower())).ToList();
                    }

                    // Sorting.
                    data = this.salaryprocessColumnWithOrder(order, orderDir, data);

                    // Filter record count.
                    int recFilter = data.Count;


                    if (pageSize != -1)
                    {
                        data = data.Skip(startRec).Take(pageSize).ToList();
                    }
                    else
                    {
                        data = data.ToList();
                    }

                    // Loading drop down lists.
                    result = this.Json(new { draw = Convert.ToInt32(draw), recordsTotal = totalRecords, recordsFiltered = recFilter, data = data }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }

            // Return info.
            return(result);
        }
        public SalaryProcessDetailsVM SaveSalaryProcessD(SalaryProcessDetailsVM SPDV)
        {
            string deptcode1 = SPDV.Deptcode == "0" ? "" : SPDV.Deptcode;
            string vloc1     = SPDV.VisaLocation1 == "0" ? "" : SPDV.VisaLocation1;
            string Month     = "";
            string year      = "";
            List <SalaryProcessDetailsListItem> objList = null;

            try
            {
                var Drecord = new List <string>();
                List <SalaryProcessDetailsListItem> ObjList = new List <SalaryProcessDetailsListItem>();
                ObjList.AddRange(SPDV.salaryList.Select(m => new SalaryProcessDetailsListItem
                {
                    //country = m.country,
                    //Division = m.Division,
                    //Tyear = m.Tyear,
                    //Tmonth = m.Tmonth,
                    Empcode = m.Empcode,
                    //Empname = m.Empname,
                    //ProfCode = m.ProfCode,
                    //DepCode = m.DepCode,
                    //ComnPrjcode = m.ComnPrjcode,
                    //VisaLocation = m.VisaLocation,
                    //WorkLocation = m.WorkLocation,
                    //Total_Days = m.Total_Days,
                    //Worked_Days = m.Worked_Days,
                    //loan_amt = m.loan_amt,
                    //adn_amount = m.adn_amount,
                    //ExtraOTAmt = m.ExtraOTAmt,
                    //NOTAmt = m.NOTAmt,
                    //HOTAmt = m.HOTAmt,
                    //WOTAmt = m.WOTAmt,
                    //NetSalary = m.NetSalary,
                    //flag = m.flag,
                    //Salary_Paid = m.Salary_Paid,
                    //Incentive_Paid = m.Incentive_Paid
                }).ToList());
                int n      = 0;
                int countl = 0;
                n = ObjList.Count;

                if (!SPDV.EditFlag)
                {
                    using (TransactionScope scope1 = new TransactionScope())
                    {
                        DateTime dte     = Convert.ToDateTime(SPDV.Process_Date);
                        string   saldate = dte.ToString("yyyy-MM-dd");
                        Month = dte.ToString("MM");
                        DateTime dte1 = Convert.ToDateTime(SPDV.Process_Date);
                        year = dte.ToString("yyyy");
                        string         yeardata  = SPDV.Process_Date.ToString("yyyy");
                        string         monthdata = SPDV.Process_Date.ToString("MM");
                        SqlParameter[] param     = { new SqlParameter("@CmpyCode", SPDV.CmpyCode),
                                                     new SqlParameter("@DivCode",      SPDV.DivisionCode),
                                                     new SqlParameter("@Year",         yeardata),
                                                     new SqlParameter("@Month",        monthdata),
                                                     new SqlParameter("@UserName",     SPDV.UserName),
                                                     new SqlParameter("@PRSP001_CODE", SPDV.PRSP001_Code),
                                                     new SqlParameter("Process_Date",  SPDV.Process_Date),
                                                     new SqlParameter("@DeptCode",     deptcode1),
                                                     new SqlParameter("@visaloction",  vloc1) };
                        bool           result = _EzBusinessHelper.ExecuteNonQuery("usp_SaveDataSalaryProcess", param);
                        int            pno    = _EzBusinessHelper.ExecuteScalar("Select Nos from PARTTBL001 where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + PurchaseMgmtConstants.SalaryProcessHeader + "' ");
                        if (result == true)
                        {
                            while (n > 0)
                            {
                                // decimal Stats1 = _EzBusinessHelper.ExecuteScalarDec("Select count(*) as [count1] from PRSP002 where CmpyCode='" + SPDV.CmpyCode + "'  and flag=0 and empcode='" + ObjList[n - 1].Empcode + "'");
                                int loanstatus = _EzBusinessHelper.ExecuteScalar("select count(*) from PRLA001 prl inner join PRLA002 la on prl.PRLA001_CODE=la.PRLA001_CODE and prl.CmpyCode=la.CmpyCode where EmpCode='" + ObjList[n - 1].Empcode + "' and la.TMONTH='" + Month + "' and la.TYEAR='" + year + "'");
                                if (loanstatus > 0)
                                {
                                    countl = _EzBusinessHelper.ExecuteNonQuery("UPDATE A SET Paid = 'Y' from PRLA002 A INNER JOIN PRLA001 RA ON A.PRLA001_CODE = RA.PRLA001_CODE and a.CmpyCode = ra.CmpyCode where a.TMONTH ='" + Month + "' and a.TYEAR ='" + year + "' and ra.EmpCode ='" + ObjList[n - 1].Empcode + "' and a.CmpyCode ='" + SPDV.CmpyCode + "'");
                                }

                                n = n - 1;
                            }
                        }

                        //if (bool flg == true)
                        //{
                        //_EzBusinessHelper.ExecuteNonQuery(" UPDATE PARTTBL001 SET Nos = " + (pno + 1) + " where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + PurchaseMgmtConstants.SalaryProcessHeader + "'");
                        // _EzBusinessHelper.ExecuteNonQuery("UPDATE PARTTBL001 SET Nos = " + (pno + 1) + " where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + PurchaseMgmtConstants.SalaryProcessHeader + "'");
                        _EzBusinessHelper.ActivityLog(SPDV.CmpyCode, SPDV.UserName, "Add Salary Process", SPDV.PRSP001_Code, Environment.MachineName);
                        SPDV.SaveFlag     = true;
                        SPDV.ErrorMessage = string.Empty;
                        //}



                        scope1.Complete();
                    }
                    return(SPDV);
                }
                else
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        while (n > 0)



                        {
                            var StatsEdit = _EzBusinessHelper.ExecuteScalarDec("Select count(*) from PRSPD001 where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + SPDV.PRSP001_Code + "' and Flag=0");
                            if (StatsEdit != 0)
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.Append("CmpyCode='" + SPDV.CmpyCode + "',");
                                //sb.Append("Sno='" + ObjList[n - 1].Sno + "',");
                                //sb.Append("Code='" + ObjList[n - 1].Code + "',");
                                //sb.Append("EmpName='" + ObjList[n - 1].EmpName + "',");
                                //sb.Append("ProjectCode='"+ ObjList[n - 1].ProjectCode + "',");
                                //sb.Append("EmpCode='" + ObjList[n - 1].EmpCode + "',");
                                //sb.Append("WorkingDay='" + ObjList[n - 1].WorkingDay + "',");
                                //sb.Append("Present='" + ObjList[n - 1].Present + "',");
                                //sb.Append("LossDays='" + ObjList[n - 1].LossDays + "',");
                                //sb.Append("Absent='" + ObjList[n - 1].Absent + "',");
                                //sb.Append("Leaves='" + ObjList[n - 1].Leaves + "',");
                                //sb.Append("SickLeave='" + ObjList[n - 1].SickLeaves + "',");
                                //sb.Append("WeeklyOff='" + ObjList[n - 1].WeeklyOff + "',");
                                //sb.Append("Holiday='" + ObjList[n - 1].Holiday + "',");
                                //sb.Append("NormalOTHrs='" + ObjList[n - 1].NormalOTHrs + "',");
                                //sb.Append("HolidayOTHrs='" + ObjList[n - 1].HolidayOTHrs + "',");
                                //sb.Append("WeeklyOffOTHrs='" + ObjList[n - 1].WeeklyOffOTHrs + "',");
                                //sb.Append("ExtraOTHrs='" + ObjList[n - 1].ExtraOTHrs + "',");
                                //sb.Append("FExtraOTHrs='" + ObjList[n - 1].FExtraOTHrs + "',");
                                //sb.Append("TotalAddition='" + ObjList[n - 1].MonthlyAddition + "',");
                                //sb.Append("TotalEarning='" + ObjList[n - 1].TotalEarning + "',");
                                //sb.Append("TotalDeduction='" + ObjList[n - 1].TotalDeduction + "',");
                                //sb.Append("LoanDeduction='" + ObjList[n - 1].LoanDeduction + "',");
                                sb.Append("NetSalary='" + ObjList[n - 1].NetSalary + "')");
                                _EzBusinessHelper.ExecuteNonQuery("update PRSPD001 set'" + sb.ToString() + "' where compycode='" + SPDV.CmpyCode + "'and code='" + SPDV.PRSP001_Code + "' and Flag=0 ");

                                _EzBusinessHelper.ActivityLog(SPDV.CmpyCode, SPDV.UserName, "Update Salary Process", SPDV.PRSP001_Code, Environment.MachineName);

                                SPDV.SaveFlag     = true;
                                SPDV.ErrorMessage = string.Empty;
                            }
                            else
                            {
                                SPDV.SaveFlag     = false;
                                SPDV.ErrorMessage = "Record not available";
                            }
                            n = n - 1;
                        }
                        var SalaryEdit = _EzBusinessHelper.ExecuteNonQuery("Select * from PRSPH001 where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + SPDV.PRSP001_Code + "' and Flag=0");
                        if (SalaryEdit != 0)
                        {
                            _EzBusinessHelper.ExecuteNonQuery("update PRSPH001 set CmpyCode='" + SPDV.CmpyCode + "',Code='" + SPDV.PRSP001_Code + "',Month='" + Month + "',year='" + year + "' where CmpyCode='" + SPDV.CmpyCode + "' and Code='" + SPDV.PRSP001_Code + "' and Flag=0");
                            SPDV.SaveFlag     = true;
                            SPDV.ErrorMessage = string.Empty;
                        }
                        else
                        {
                            SPDV.SaveFlag     = false;
                            SPDV.ErrorMessage = "Record not available";
                        }
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                SPDV.SaveFlag = false;
                //  unit.ErrorMessage = exceptionMessage;
            }

            return(SPDV);
        }