public ActionResult ForEmployee(SalaryInfo info) { using (var dataClass = new DataClassesDataContext()) { if (!info.Month.HasValue) { info.Month = DateTime.Now.AddMonths(-1); } var data = SalaryCalculator.Get(UserID, Employee.ID, info, false); var isAdmin = dataClass.CheckCurrentLoginInAdmin(UserID).SingleOrDefault().IsAdmin; var model = new SalaryDetail() { SalaryCalculator = data, IsAdmin = (bool)isAdmin }; if (Request.IsAjaxRequest()) { return(Json(new { html = RenderPartialViewToString(Views.ForEmployeePartial, model) }, JsonRequestBehavior.AllowGet)); } return(View(Views.ForEmployee, model)); } }
public static SalaryCalculator Get(int userID, int employeeID, SalaryInfo info, bool?find = null, EmployeeInfo employeeInfo = null) { var result = new SalaryCalculator(new EmployeeFilter(), info, employeeInfo); try { using (var con = Repo.DB.SKtimeManagement) { if (find.HasValue && find.Value) { var dbInfo = con.Query <SalaryInfo>(String.Format("select top 1 * from Salary where EmployeeID = {0} order by Month desc", result.Info.EmployeeID)).FirstOrDefault(); if (dbInfo != null) { result = new SalaryCalculator(new EmployeeFilter(), dbInfo, employeeInfo); } } if (employeeInfo == null) { result.EmployeeInfo = con.Query <EmployeeInfo>( String.Format(@"select e.*, l.ID as [LoginID], l.Username, s.Name as [StoreName], isnull(sum(o.Total - o.Discount), 0) as [CurrentSale] from Employee e left join Login l on l.EmployeeID = e.ID left join Store s on e.StoreID = s.ID left join [Order] o on o.EmployeeID = e.ID and o.Removed = 0 and o.Status <> N'{1}' where e.Status = 'active' and e.ID = {0} group by e.AdditionalSalary, e.Address, e.BaseSalary, e.BussinessID, e.ID, e.Image, e.MonthlySale, e.Name, e.OffDays, e.Phone, e.Position, e.DOB, e.StartDate, e.Status, e.StoreID, e.Summary, e.WorkDays, e.WorkTime, e.EndDate, e.BankNumber, e.BankName, e.BankBranch, e.WorkStatus, l.ID, l.Username, s.Name" , info.EmployeeID, OrderStatus.Refunded)).FirstOrDefault(); } //result.Offsets = SaleOffset.Get(userID, employeeID, info.ID); result.OffDays = con.Query <EmployeeOffDay>(String.Format("select * from EmployeeOffDay where EmployeeID = {0} order by OffDate desc", info.EmployeeID)).ToList(); if (result.EmployeeInfo.StoreID.HasValue) { result.Orders = con.Query <ExportRecord>(GetStoreOrders(userID, employeeID, result.EmployeeInfo.StoreID.Value, result.From, result.To)).ToList(); } else { result.Orders = new List <ExportRecord>(); } result.Fines = con.Query <EmployeeFine>(EmployeeFine.Query(result.EmployeeInfo.BussinessID, new EmployeeFineFilter(result.EmployeeInfo.ID, result.From, result.To))).ToList(); result.SaleTotal = result.Orders.Where(i => i.EmployeeID == info.EmployeeID).Sum(i => i.Paid); result.StoreSale = result.Orders.Sum(i => i.Paid); //result.SaleRate = result.Offsets.Count == 0 ? 0 : result.Offsets.FirstOrDefault(i => result.SaleTotal >= i.Offset).Value; result.OffCount = result.OffDays.Where(i => i.OffDate >= result.From && i.OffDate <= result.To).Count() + info.AdditionalOffDays; if (find.HasValue && !find.Value) { con.Execute(String.Format( @"delete Salary where EmployeeID = {0} and Month = '{1}' insert into Salary(EmployeeID, Month, OffValue, ValidOffDays, AdditionalOffDays, EmployeeCount, SalePoint, SaleAdd, Paid, Other, Note, CalculatedTotal, BaseSalary) values ({0}, '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, N'{10}', {11}, {12})", result.Info.EmployeeID, result.From.ToString(Constants.DatabaseDateString), result.Info.OffValue, result.Info.ValidOffDays, result.Info.AdditionalOffDays, result.Info.EmployeeCount, result.Info.SalePoint, result.Info.SaleAdd, result.Info.Paid, result.Info.Other, result.Info.Note, result.Total, result.BaseSalary)); } } } catch { } return(result); }
public SalaryCalculator(EmployeeFilter filter, SalaryInfo info, EmployeeInfo employeeInfo = null) { EmployeeFilter = filter; EmployeeInfo = employeeInfo; Info = info; Paid = info.Paid; Other = info.Other; var time = DateTime.Now.AddMonths(-1); if (info.Month.HasValue) { time = info.Month.Value; } From = new DateTime(time.Year, time.Month, 1); To = From.AddMonths(1); Note = info.Note; }