public void AddActual(ManagerBonusDTO managerBonusDTO) { DataBaseUtility db = new DataBaseUtility(); string query = "INSERT INTO [dbo].[ManagerBonus] ([StoreId] ,[LastDateOFMonth] ,[FoodCost] ,[LaborCost] ,[FoodLaborCost] ,[SalesIncrease] ,[CustomerIndex] ,[CustomerComplaint] ,[Catering] ,[SubInspection] ,[CreatedDateTime] ,[LastUpdateDateTime]) " + " VALUES (" + SQLUtility.getInteger(managerBonusDTO.StoreId) + ",'" + SQLUtility.FormateDateYYYYMMDD(managerBonusDTO.LastDateOFMonth) + "',0,0,0,0,0,0,0,0,'" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "','" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "')"; db.ExecuteUpdate(query); }
public void AddBounus(ManagerBonusDTO managerBonusDTO, bool isZeroBasis) { DataBaseUtility db = new DataBaseUtility(); String query = "INSERT INTO [dbo].[ManagerBonus] ([StoreId] ,[FirstDateOfMonth],[LastDateOfMonth],[FoodCost] ,[LaborCost] ,[FoodLaborCost] ,[SalesIncrease] ,[CustomerIndex] ,[CustomerComplaint] " + " ,[Catering] ,[SubInspection],[IsZeroBasis] ,[CreatedDateTime] ,[LastUpdateDateTime]) " + " VALUES (" + SQLUtility.getInteger(managerBonusDTO.StoreId) + ", '" + SQLUtility.FormateDateYYYYMMDD(managerBonusDTO.FirstDateOFMonth) + "','" + SQLUtility.FormateDateYYYYMMDD(managerBonusDTO.LastDateOFMonth) + "'," + SQLUtility.getDouble(managerBonusDTO.FoodCost) + "," + SQLUtility.getDouble(managerBonusDTO.LaborCost) + "," + SQLUtility.getDouble(managerBonusDTO.FoodLaborCost) + "," + SQLUtility.getDouble(managerBonusDTO.SalesIncrease) + ", " + " " + SQLUtility.getDouble(managerBonusDTO.CustomerIndex) + "," + SQLUtility.getDouble(managerBonusDTO.CustomerComplaint) + "," + SQLUtility.getDouble(managerBonusDTO.Catering) + ", " + " " + SQLUtility.getDouble(managerBonusDTO.SubInspection) + ",'" + isZeroBasis + "' , '" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "','" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "') "; db.ExecuteUpdate(query); }
public ManagerBonusDTO GetActualBounus(int storeId, DateTime startDate, DateTime endDate) { int totalWeekCount = ValidationUtility.GetNumOfWeekInMonth(startDate); if (totalWeekCount == 0) { totalWeekCount = 1; } ManagerBonusDTO managerBonusDTO = null; DataBaseUtility db = new DataBaseUtility(); SqlConnection con = null; try { string query = "select * from dbo.ManagerBonus where StoreId = " + SQLUtility.getInteger(storeId) + " and IsZeroBasis=" + SQLUtility.getString(false.ToString()) + " " + " and FirstDateOfMonth='" + SQLUtility.FormateDateYYYYMMDD(startDate) + "' and LastDateOfMonth = '" + SQLUtility.FormateDateYYYYMMDD(endDate) + "' "; con = db.OpenConnection(); SqlCommand comm = db.getSQLCommand(query, con); SqlDataReader reader = comm.ExecuteReader(); if (reader.Read()) { int id = ValidationUtility.ToInteger(reader["Id"].ToString()); int sId = ValidationUtility.ToInteger(reader["StoreId"].ToString()); double foodCost = ValidationUtility.ToDouble(reader["FoodCost"].ToString()); double laborCost = ValidationUtility.ToDouble(reader["LaborCost"].ToString()); double foodLaborCost = ValidationUtility.ToDouble(reader["FoodLaborCost"].ToString()); double salesIncrease = ValidationUtility.ToDouble(reader["SalesIncrease"].ToString()); double customerIndex = ValidationUtility.ToDouble(reader["CustomerIndex"].ToString()); double customerComplaint = ValidationUtility.ToDouble(reader["CustomerComplaint"].ToString()); double catering = ValidationUtility.ToDouble(reader["Catering"].ToString()); double subInspection = ValidationUtility.ToDouble(reader["SubInspection"].ToString()); managerBonusDTO = new ManagerBonusDTO { Id = id, StoreId = sId, FoodCost = foodCost / totalWeekCount, LaborCost = laborCost / totalWeekCount, FoodLaborCost = foodLaborCost / totalWeekCount, SalesIncrease = salesIncrease / totalWeekCount, CustomerIndex = customerIndex / totalWeekCount, CustomerComplaint = customerComplaint, Catering = catering, SubInspection = subInspection }; } reader.Close(); comm.Dispose(); } catch (Exception ex) { log.Error(" Exception in GetActualBounus Method ", ex); } finally { db.CloseConnection(con); } return managerBonusDTO; }
//Add or Update Method public ManagerBonusDTO CalculateManagerBonus(DateTime selectDate, ArrayList storeList) { ManagerBonusDTO managerBonusDTO = new ManagerBonusDTO(); StoreDTO storeDTO = (StoreDTO)storeList[0]; DateTime givenMontWeekStartDate = ValidationUtility.MonthWeekStartDate(selectDate); DateTime currentMonthWeekStartDate = ValidationUtility.MonthWeekStartDate(DateTime.Now); if (givenMontWeekStartDate.Date.Equals(currentMonthWeekStartDate.Date)) { bool isWeekRemain = false; DateTime everyWeekStartDate = givenMontWeekStartDate; DateTime montEndDate = ValidationUtility.MonthWeekEndDate(DateTime.Now); int complaintConut = CustomerComplaintCount(storeDTO.Id, givenMontWeekStartDate, montEndDate.AddDays(6)); double foodCostOfMonth = 0; double laborCostOfMonth = 0; while (!isWeekRemain) { WeeklyPaperworkDTO dto = null; if (montEndDate.Date.Equals(everyWeekStartDate.Date)) { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; isWeekRemain = true; } else { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; } everyWeekStartDate = everyWeekStartDate.AddDays(7); } managerBonusDTO.StoreId = storeDTO.Id; managerBonusDTO.FirstDateOFMonth = givenMontWeekStartDate.Date; managerBonusDTO.LastDateOFMonth = montEndDate.Date.AddDays(6); managerBonusDTO.CustomerComplaint = complaintConut; managerBonusDTO.FoodCost = foodCostOfMonth; managerBonusDTO.LaborCost = laborCostOfMonth; managerBonusDTO.FoodLaborCost = foodCostOfMonth + laborCostOfMonth; managerBonusDTO.IsZeroBasis = false; } else if (givenMontWeekStartDate.Date < currentMonthWeekStartDate.Date) { bool isWeekRemain = false; DateTime everyWeekStartDate = givenMontWeekStartDate; DateTime montEndDate = ValidationUtility.MonthWeekEndDate(selectDate); int complaintConut = CustomerComplaintCount(storeDTO.Id, givenMontWeekStartDate, montEndDate.AddDays(6)); double foodCostOfMonth = 0; double laborCostOfMonth = 0; while (!isWeekRemain) { WeeklyPaperworkDTO dto = null; if (montEndDate.Date.Equals(everyWeekStartDate.Date)) { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; isWeekRemain = true; } else { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; } everyWeekStartDate = everyWeekStartDate.AddDays(7); } managerBonusDTO.StoreId = storeDTO.Id; managerBonusDTO.FirstDateOFMonth = givenMontWeekStartDate.Date; managerBonusDTO.LastDateOFMonth = montEndDate.Date.AddDays(6); managerBonusDTO.CustomerComplaint = complaintConut; managerBonusDTO.FoodCost = foodCostOfMonth; managerBonusDTO.LaborCost = laborCostOfMonth; managerBonusDTO.FoodLaborCost = foodCostOfMonth + laborCostOfMonth; managerBonusDTO.IsZeroBasis = false; } else if (givenMontWeekStartDate.Date > currentMonthWeekStartDate.Date) { bool isWeekRemain = false; givenMontWeekStartDate = currentMonthWeekStartDate; DateTime everyWeekStartDate = givenMontWeekStartDate; DateTime montEndDate = ValidationUtility.MonthWeekEndDate(DateTime.Now); int complaintConut = CustomerComplaintCount(storeDTO.Id, givenMontWeekStartDate, montEndDate.AddDays(6)); double foodCostOfMonth = 0; double laborCostOfMonth = 0; while (!isWeekRemain) { WeeklyPaperworkDTO dto = null; if (montEndDate.Date.Equals(everyWeekStartDate.Date)) { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; isWeekRemain = true; } else { dto = GetWeeklyPaperWork(everyWeekStartDate, storeList); foodCostOfMonth = foodCostOfMonth + dto.CostPercent; laborCostOfMonth = laborCostOfMonth + dto.LaborCostPercent; } everyWeekStartDate = everyWeekStartDate.AddDays(7); } managerBonusDTO.StoreId = storeDTO.Id; managerBonusDTO.FirstDateOFMonth = givenMontWeekStartDate.Date; managerBonusDTO.LastDateOFMonth = montEndDate.Date.AddDays(6); managerBonusDTO.CustomerComplaint = complaintConut; managerBonusDTO.FoodCost = foodCostOfMonth; managerBonusDTO.LaborCost = laborCostOfMonth; managerBonusDTO.FoodLaborCost = foodCostOfMonth + laborCostOfMonth; managerBonusDTO.IsZeroBasis = false; } return managerBonusDTO; }
public void UpdateZeroBasis(ManagerBonusDTO managerBonusDTO) { DataBaseUtility db = new DataBaseUtility(); string query = "update dbo.ManagerBonus set FoodCost=" + SQLUtility.getDouble(managerBonusDTO.FoodCost) + ",LaborCost=" + SQLUtility.getDouble(managerBonusDTO.LaborCost) + ",FoodLaborCost=" + SQLUtility.getDouble(managerBonusDTO.FoodLaborCost) + ", " + " SalesIncrease=" + SQLUtility.getDouble(managerBonusDTO.SalesIncrease) + ",CustomerIndex=" + SQLUtility.getDouble(managerBonusDTO.CustomerIndex) + ",CustomerComplaint=" + SQLUtility.getDouble(managerBonusDTO.CustomerComplaint) + ", " + " Catering=" + SQLUtility.getDouble(managerBonusDTO.Catering) + ",SubInspection=" + SQLUtility.getDouble(managerBonusDTO.SubInspection) + ", LastUpdateDateTime='" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "' " + " where Id=" + SQLUtility.getInteger(managerBonusDTO.Id) + " and StoreId=" + SQLUtility.getInteger(managerBonusDTO.StoreId) + " and IsZeroBasis='true' "; db.ExecuteUpdate(query); }
public void UpdateSubInspectionValue(ManagerBonusDTO managerBonusDTO) { DataBaseUtility db = new DataBaseUtility(); string query = "update dbo.ManagerBonus set SubInspection=" + SQLUtility.getDouble(managerBonusDTO.SubInspection) + ", LastUpdateDateTime='" + SQLUtility.FormateDateYYYYMMDDWtithTime(DateTime.Now) + "' where Id=" + SQLUtility.getInteger(managerBonusDTO.Id) + " and StoreId=" + SQLUtility.getInteger(managerBonusDTO.StoreId) + ""; db.ExecuteUpdate(query); }
public bool IsZeroBasisExist(ManagerBonusDTO managerBonusDTO) { bool isExist = false; DataBaseUtility db = new DataBaseUtility(); SqlConnection conn = null; try { conn = db.OpenConnection(); string query = "select * from dbo.ManagerBonus where StoreId=" + SQLUtility.getInteger(managerBonusDTO.StoreId) + " and LastDateOFMonth='" + SQLUtility.FormateDateYYYYMMDD(managerBonusDTO.LastDateOFMonth) + "'"; SqlCommand comm = db.getSQLCommand(query, conn); SqlDataReader reader = comm.ExecuteReader(); if (reader.Read()) { isExist = true; } reader.Close(); comm.Dispose(); } catch (Exception ex) { log.Error("Exception in IsZeroBasisExist", ex); } finally { db.CloseConnection(conn); } return isExist; }
// Get Total DTO public ManagerBonusDTO GetMaximumValue(ManagerBonusDTO differenceDTO) { ManagerBonusDTO managerBonusDTO = null; try { double fcost = Math.Max(differenceDTO.FoodCost * 50, -200); double lCost = Math.Max(differenceDTO.LaborCost * 50, -200); double flCos = Math.Max(differenceDTO.FoodLaborCost * 50, -200); double salesIncrease = Math.Max(differenceDTO.SalesIncrease * 50, -200); double customerIndex = Math.Max(differenceDTO.CustomerIndex * 50, -200); double customerComplaint = Math.Max(differenceDTO.CustomerComplaint * 50, -200); double catering = Math.Max(differenceDTO.Catering * 50, -200); double subInspection = Math.Max(differenceDTO.SubInspection * 50, -200); double totalAmount = fcost + lCost + flCos + salesIncrease + customerIndex + customerComplaint + catering + subInspection; managerBonusDTO = new ManagerBonusDTO { FoodCost = fcost, LaborCost = lCost, FoodLaborCost = flCos, SalesIncrease = salesIncrease, CustomerIndex = customerIndex, CustomerComplaint = customerComplaint, Catering = catering, SubInspection = subInspection, Total = totalAmount }; } catch (Exception ex) { log.Error("Exception in GetMaximumValue method", ex); } return managerBonusDTO; }
public ArrayList GetManagerBonus(int storeId, DateTime EndDateOFMonth) { ArrayList list = new ArrayList(); DataBaseUtility db = new DataBaseUtility(); SqlConnection conn = null; try { string query = "select * from dbo.ManagerBonus where StoreId=" + SQLUtility.getInteger(storeId) + " and LastDateOFMonth='" + SQLUtility.FormateDateYYYYMMDD(EndDateOFMonth) + "' "; conn = db.OpenConnection(); SqlCommand comm = db.getSQLCommand(query, conn); SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { int id = ValidationUtility.ToInteger(reader["Id"].ToString()); int sId = ValidationUtility.ToInteger(reader["StoreId"].ToString()); double foodCost = ValidationUtility.ToDouble(reader["FoodCost"].ToString()); double laborCost = ValidationUtility.ToDouble(reader["LaborCost"].ToString()); double foodLaborCost = ValidationUtility.ToDouble(reader["FoodLaborCost"].ToString()); double salesIncrease = ValidationUtility.ToDouble(reader["SalesIncrease"].ToString()); double customerIndex = ValidationUtility.ToDouble(reader["CustomerIndex"].ToString()); double customerComplaint = ValidationUtility.ToDouble(reader["CustomerComplaint"].ToString()); double catering = ValidationUtility.ToDouble(reader["Catering"].ToString()); double subInspection = ValidationUtility.ToDouble(reader["SubInspection"].ToString()); ManagerBonusDTO managerBonusDTO = new ManagerBonusDTO { Id = id, StoreId = sId, FoodCost = foodCost, LaborCost = laborCost, FoodLaborCost = foodLaborCost, SalesIncrease = salesIncrease, CustomerIndex = customerIndex, CustomerComplaint = customerComplaint, Catering = catering, SubInspection = subInspection }; list.Add(managerBonusDTO); } reader.Close(); comm.Dispose(); } catch (Exception ex) { log.Error("Exception in GetManagerBonus Method", ex); } finally { db.CloseConnection(conn); } return list; }
// Difference public ManagerBonusDTO GetDifferenceDTO(ManagerBonusDTO actualDTO, ManagerBonusDTO zetoBasisDTO) { ManagerBonusDTO differenceDTO = new ManagerBonusDTO(); try { //ManagerBonusDTO actualDTO = (ManagerBonusDTO)storeBonusList[0]; //ManagerBonusDTO zetoBasisDTO = (ManagerBonusDTO)storeBonusList[1]; if (ValidationUtility.IsNull(actualDTO)) { actualDTO = new ManagerBonusDTO(); } if (ValidationUtility.IsNull(zetoBasisDTO)) { zetoBasisDTO = new ManagerBonusDTO(); } differenceDTO.FoodCost = zetoBasisDTO.FoodCost - actualDTO.FoodCost; differenceDTO.LaborCost = zetoBasisDTO.LaborCost - actualDTO.LaborCost; differenceDTO.FoodLaborCost = zetoBasisDTO.FoodLaborCost - actualDTO.FoodLaborCost; differenceDTO.SalesIncrease = zetoBasisDTO.SalesIncrease - actualDTO.SalesIncrease; differenceDTO.CustomerIndex = zetoBasisDTO.CustomerIndex - actualDTO.CustomerIndex; differenceDTO.CustomerComplaint = zetoBasisDTO.CustomerComplaint - (actualDTO.CustomerComplaint * -20); differenceDTO.Catering = zetoBasisDTO.Catering - actualDTO.Catering; double newSubInspection = 0; if (actualDTO.SubInspection == 0) { newSubInspection = 50; } else { newSubInspection = -50; } differenceDTO.SubInspection = zetoBasisDTO.SubInspection - newSubInspection; // total = GetMaximumValue(differenceDTO); } catch (Exception ex) { log.Error("Exception in GetTotalBonus Method", ex); } return differenceDTO; }
public JsonResult UpdateZeroBasisValues(string tId, string sId, string foodCost, string laborCost, string salesIncrease, string customerIndex, string customerComplaint, string catering, string subInspection) { ManagerBonusModel managerBonusModel = new ManagerBonusModel(); ManagerBonusDTO managerBonusDTO = new ManagerBonusDTO(); double fCost = ValidationUtility.ToDouble(foodCost); double lCost = ValidationUtility.ToDouble(laborCost); double foodLaborCost = fCost + lCost; managerBonusDTO.Id = ValidationUtility.ToInteger(tId); managerBonusDTO.StoreId = ValidationUtility.ToInteger(sId); managerBonusDTO.FoodCost = fCost; managerBonusDTO.LaborCost = lCost; managerBonusDTO.FoodLaborCost = foodLaborCost; managerBonusDTO.SalesIncrease = ValidationUtility.ToDouble(salesIncrease); managerBonusDTO.CustomerIndex = ValidationUtility.ToDouble(customerIndex); managerBonusDTO.CustomerComplaint = ValidationUtility.ToDouble(customerComplaint); managerBonusDTO.Catering = ValidationUtility.ToDouble(catering); managerBonusDTO.SubInspection = ValidationUtility.ToDouble(subInspection); managerBonusModel.UpdateZeroBasis(managerBonusDTO); ResponseDTO responseDTO = new ResponseDTO { Error = "Success", Message = "Update Successfully" }; return Json(responseDTO, JsonRequestBehavior.AllowGet); }
public JsonResult UpdateSubInspection(string tId, string sId, string subInspection) { ManagerBonusModel managerBonusModel = new ManagerBonusModel(); ManagerBonusDTO managerBonusDTO = new ManagerBonusDTO(); managerBonusDTO.Id = ValidationUtility.ToInteger(tId); managerBonusDTO.StoreId = ValidationUtility.ToInteger(sId); managerBonusDTO.SubInspection = ValidationUtility.ToDouble(subInspection); managerBonusModel.UpdateSubInspectionValue(managerBonusDTO); ResponseDTO responseDTO = new ResponseDTO { Error = "Success", Message = "Sub Inspection Update Successfully" }; return Json(responseDTO, JsonRequestBehavior.AllowGet); }
public JsonResult AddZeroBasis(String selectDate, string foodCost, string laborCost, string salesIncrease, string customerIndex, string customerComplaint, string catering, string subInspection) { ManagerBonusModel managerBonusModel = new ManagerBonusModel(); ArrayList storeList = ValidationUtility.GetStoreList(false); double fCost = ValidationUtility.ToDouble(foodCost); double lCost = ValidationUtility.ToDouble(laborCost); double foodLaborCost = fCost + lCost; DateTime formatedDate; DateTime givenMontWeekStartDate; DateTime montEndDate; if (!ValidationUtility.IsNull(selectDate)) { formatedDate = ValidationUtility.ToDate(selectDate); givenMontWeekStartDate = ValidationUtility.MonthWeekStartDate(formatedDate); montEndDate = ValidationUtility.MonthWeekEndDate(formatedDate); } else { formatedDate = DateTime.Now; givenMontWeekStartDate = ValidationUtility.MonthWeekStartDate(formatedDate); montEndDate = ValidationUtility.MonthWeekEndDate(formatedDate); } ResponseDTO responseDTO = null; foreach (StoreDTO storeDTO in storeList) { ManagerBonusDTO managerBonusDTO = new ManagerBonusDTO(); managerBonusDTO.StoreId = storeDTO.Id; managerBonusDTO.FirstDateOFMonth = givenMontWeekStartDate.Date; managerBonusDTO.LastDateOFMonth = montEndDate.Date.AddDays(6); managerBonusDTO.FoodCost = fCost; managerBonusDTO.LaborCost = lCost; managerBonusDTO.FoodLaborCost = foodLaborCost; managerBonusDTO.SalesIncrease = ValidationUtility.ToDouble(salesIncrease); managerBonusDTO.CustomerIndex = ValidationUtility.ToDouble(customerIndex); managerBonusDTO.CustomerComplaint = ValidationUtility.ToDouble(customerComplaint); managerBonusDTO.Catering = ValidationUtility.ToDouble(catering); managerBonusDTO.SubInspection = ValidationUtility.ToDouble(subInspection); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(managerBonusDTO.StoreId, managerBonusDTO.FirstDateOFMonth, managerBonusDTO.LastDateOFMonth); //if (!managerBonusModel.IsZeroBasisExist(managerBonusDTO)) //{ if (ValidationUtility.IsNull(zeroBasisDTO)) { managerBonusModel.AddBounus(managerBonusDTO, true); responseDTO = new ResponseDTO { Error = "Success", Message = "Add Successfully" }; } else { responseDTO = new ResponseDTO { Error = "Error", Message = "Records Allready Exists Now you can Update Only" }; } } return Json(responseDTO, JsonRequestBehavior.AllowGet); }
public double GetMaximumValue(ManagerBonusDTO differenceDTO) { double totalAmount = 0.0; try { double fcost = Math.Max(differenceDTO.FoodCost * 50, -200); double lCost = Math.Max(differenceDTO.LaborCost * 50, -200); double flCos = Math.Max(differenceDTO.FoodLaborCost * 50, -200); double salesIncrease = Math.Max(differenceDTO.SalesIncrease * 50, -200); double customerIndex = Math.Max(differenceDTO.CustomerIndex * 50, -200); double customerComplaint = Math.Max(differenceDTO.CustomerComplaint * 50, -200); double catering = Math.Max(differenceDTO.Catering * 50, -200); double subInspection = Math.Max(differenceDTO.SubInspection * 50, -200); totalAmount = fcost + lCost + flCos + salesIncrease + customerIndex + customerComplaint + catering + subInspection; } catch (Exception ex) { log.Error("Exception in GetMaximumValue method",ex); } return totalAmount; }