using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using HRM.BO; using System.Data; using HRM.DA; using System.Text; using Newtonsoft.Json; using static System.Runtime.InteropServices.JavaScript.JSType; using Microsoft.CodeAnalysis.VisualBasic.Syntax; using NPOI.SS.Formula.Functions; using NPOI.POIFS.Crypt.Dsig; using Microsoft.AspNetCore.Authorization; using System.IO; using Payroll.Service; using System.Drawing.Drawing2D; using static iTextSharp.awt.geom.Point2D; using NPOI.SS.Formula.Eval; using System.Globalization; using Payroll.BO; using Ease.Core.Model; namespace HRM.UI.Controllers.Payroll { [Route("api/Bonus")] [ApiController] public class BonusController : ControllerBase { private readonly IBonusService _bonusService; private readonly IBonusParameterService _bonusParameterService; private readonly IBonusProcessService _bonusProcessService; private readonly IEmployeeService _empService; private readonly IProdBonusAttnService _prodBonusAttnService; private readonly IProdBonusLineService _prodBonusLineService; private readonly IProdBonusParameterService _prodBonusParameterService; private readonly IProdBonusProcessService _prodBonusProcessService; private readonly IProdBonusSupervisorService _prodBonusSupervisorService; private readonly IProdBonusWorkScheduleService _prodBonusWorkScheduleService; private readonly IProductionBonusSetupService _productionBonusSetupService; private readonly IPRBCalculationService _prbCalculationService; private readonly IPRBKpiService _prbKpiService; private readonly IWFMovementTranService _wfMovementTranService; private readonly IGradeService _gradeService; private DataTable _uplodedData; private static List _errorOrSuccessList = new List(); public BonusController(IBonusService bonusService, IBonusParameterService bonusParameterService, IBonusProcessService bonusProcessService, IEmployeeService empService, IProdBonusAttnService prodBonusAttnService, IProdBonusLineService prodBonusLineService, IProdBonusParameterService prodBonusParameterService, IProdBonusProcessService prodBonusProcessService, IProdBonusSupervisorService prodBonusSupervisorService, IProdBonusWorkScheduleService prodBonusWorkScheduleService, IProductionBonusSetupService productionBonusSetupService, IPRBCalculationService prbCalculationService, IPRBKpiService prbKpiService, IWFMovementTranService wfMovementTranService, IGradeService gradeService) { _bonusService = bonusService; _bonusParameterService = bonusParameterService; _bonusProcessService = bonusProcessService; _empService = empService; _prodBonusAttnService = prodBonusAttnService; _prodBonusLineService = prodBonusLineService; _prodBonusParameterService = prodBonusParameterService; _prodBonusProcessService = prodBonusProcessService; _prodBonusSupervisorService = prodBonusSupervisorService; _prodBonusWorkScheduleService = prodBonusWorkScheduleService; _productionBonusSetupService = productionBonusSetupService; _prbCalculationService = prbCalculationService; _prbKpiService = prbKpiService; _wfMovementTranService = wfMovementTranService; _gradeService = gradeService; } [HttpPost] [Route("saveBonusParameter")] public ActionResult saveBonusParameter(BonusParameter termParameter) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { termParameter.PayrollTypeID = (int)currentUser.PayrollTypeID; if (termParameter.IsNew == true) { termParameter.CreatedBy = currentUser.UserID; termParameter.CreatedDate = DateTime.Today; } else { termParameter.ModifiedBy = currentUser.UserID; termParameter.ModifiedDate = DateTime.Today; } _bonusParameterService.Save(termParameter); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(termParameter); } [HttpPost] [Route("DeleteBonusParameter")] public ActionResult DeleteBonusParameter(BonusParameter termParameter) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _bonusParameterService.Delete(termParameter.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(termParameter); } [HttpGet("getAllBonusParameters")] public ActionResult GetAllBonusParameters() { List bonusParameters = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { bonusParameters = _bonusParameterService.Get(EnumStatus.Active, (int)ouser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(bonusParameters); } [HttpGet("GetUsedGrades/{termID}")] public ActionResult GetUsedGrades(int termID) { List items = new List(); try { items = _bonusParameterService.GetUsedGrades(termID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost] [Route("BonusProcess")] public ActionResult BonusProcess(dynamic processItems) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); int index = 0; List searhemp = new List(); string empid = ""; int? bonusid = null; DateTime? dBasicMonth = null; DateTime? dPayDate = null; DateTime? dCuttOfDate = null; double? CurrProcess = null; bool? IsDisburseWithSalary = null; bool? IsTaxProcess = null; foreach (var item in items) { if (index == 0) { bonusid = (int)item["bonusid"].ToObject(); dBasicMonth = (DateTime)item["basicMonth"].ToObject(); dPayDate = (DateTime)item["payDate"].ToObject(); dCuttOfDate = (DateTime)item["cuttOfDate"].ToObject(); CurrProcess = (double)item["currProcess"].ToObject(); IsDisburseWithSalary = (bool)item["isDisburseWithSalary"].ToObject(); IsTaxProcess = (bool)item["isDisburseWithSalary"].ToObject(); IsTaxProcess = (bool)item["isTaxProcess"].ToObject(); } empid = empid + (string)item["empid"].ToObject() + ","; } if (empid.Length > 0) { empid = empid.Substring(0, empid.Length - 1); } List errorOrSucess = new List(); BonusProcess prc = null; try { List employees = this._empService.GetByEmpIDs(empid, (int)currentUser.PayrollTypeID); prc = this._bonusProcessService.CalculateBonus((int)currentUser.PayrollTypeID, employees, (int)bonusid, (DateTime)dBasicMonth, (DateTime)dPayDate, (DateTime)dCuttOfDate, (double)CurrProcess, (bool)IsDisburseWithSalary, (bool)IsTaxProcess); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(prc); } [HttpPost] [Route("saveBonusProcess")] public ActionResult saveBonusProcess(BonusProcess bonusPrss) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { bonusPrss.PayrollTypeID = (int)currentUser.PayrollTypeID; if (bonusPrss.IsNew == true) { bonusPrss.CreatedBy = currentUser.UserID; bonusPrss.CreatedDate = DateTime.Today; } else { bonusPrss.ModifiedBy = currentUser.UserID; bonusPrss.ModifiedDate = DateTime.Today; } _bonusProcessService.Save(bonusPrss); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("CalculateBonusTax")] public ActionResult CalculateBonusTax(List items) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { int bonusid = items[0].BonusID; List emps = new List(); items.ForEach(x => { emps.Add(x.Employee); }); items = _bonusProcessService.CalculateBonusTax(items, emps, bonusid, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost] [Route("UndoBonusProcess")] public ActionResult UndoBonusProcess(BonusProcess bonusPrss) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _bonusProcessService.UndoBonusProcess(bonusPrss); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("ApproveBonus")] public ActionResult ApproveBonus(dynamic processItems) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); int? bonusid = (int)item["bonusid"].ToObject(); DateTime? dBasicMonth = (DateTime)item["bonusMonth"].ToObject(); try { this._bonusProcessService.ApproveBonus((int)bonusid, (DateTime)dBasicMonth, (int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpGet("GetBonusProcessDetail/{bonusID}/{bonusMonth}")] public ActionResult GetBonusProcessDetail(int bonusid, string bonusMonth) { List details = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime dDate = GlobalFunctions.GetApiDefaultDateData(bonusMonth); try { details = this._bonusProcessService.GetBonusDetails((int)currentUser.PayrollTypeID, bonusid, dDate); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(details); } [HttpGet("GetUnApprovedBonusses")] public ActionResult GetUnApprovedBonusses() { DataTable ot = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { ot = this._bonusProcessService.GetUnApprovedBonuses((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ot); } [HttpGet("IsBonusApproved/{bonusID}/{bonusMonth}")] public ActionResult IsBonusApproved(int bonusID, string bonusMonth) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime? bMonth = GlobalFunctions.GetApiDefaultDateData(bonusMonth); bool isApproved = false; try { isApproved = this._bonusProcessService.IsApproved(bonusID, (DateTime)bMonth, (int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(isApproved); } [HttpGet("GetBonusItemsForESSBonusPayslip")] public ActionResult GetBonusItemsForESSBonusPayslip() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DataTable olist = null; try { olist = _bonusProcessService.GetBonusItemsForESSBonusPayslip((int)currentUser.EmployeeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(olist); } #region Production Bonus [HttpPost] [Route("saveProductionBonusSetup")] public ActionResult saveProductionBonusSetup(ProductionBonusSetup prodBonusSet) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { if (prodBonusSet.IsNew == true) { prodBonusSet.CreatedBy = currentUser.UserID; prodBonusSet.CreatedDate = DateTime.Today; } else { prodBonusSet.ModifiedBy = currentUser.UserID; prodBonusSet.ModifiedDate = DateTime.Today; } _productionBonusSetupService.Save(prodBonusSet); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("getLayout")] public ActionResult getLayout(dynamic processItems) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime? dBasicMonth = (DateTime)item["createdDate"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); //List item = new List(); DataTable dt = null; try { dt = _productionBonusSetupService.GetLayout((DateTime)dBasicMonth); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(dt); } [HttpPost] [Route("GetLayoutMonthly")] public ActionResult GetLayoutMonthly(dynamic processItems) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime? dBasicMonth = (DateTime)item["salaryMonth"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); //List item = new List(); DataTable dt = null; try { dt = _productionBonusSetupService.GetLayoutMonthly((DateTime)dBasicMonth); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(dt); } [HttpGet("getLayoutDetails/{ID}")] public ActionResult getLayoutDetails(int ID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ProductionBonusSetup item = new ProductionBonusSetup(); //ProdBonusLine item = new ProdBonusLine(); try { item = _productionBonusSetupService.Get(ID); item.ProductionBonusLines = _prodBonusLineService.GetLineBySetupId(ID); foreach (ProdBonusLine prodLine in item.ProductionBonusLines) { prodLine.ProdBonusSupervisors = _prodBonusSupervisorService.GetByLineID(prodLine.ID); Employee oEmp = new Employee(); foreach (ProdBonusSupervisor prodSupervisor in prodLine.ProdBonusSupervisors) { oEmp = new EmployeeService().Get(prodSupervisor.EmployeeID); prodSupervisor.EmpName = oEmp.Name; prodSupervisor.EmployeeNo = oEmp.EmployeeNo; } prodLine.ProdBonusParameters = _prodBonusParameterService.GetByLineID(prodLine.ID); Department oDept = new Department(); foreach (ProdBonusParameter prodParameter in prodLine.ProdBonusParameters) { oDept = new DepartmentService().Get(prodParameter.ItemID); prodParameter.ItemType = 0; prodParameter.ItemID = oDept.ID; } prodLine.ProdBonusWorkSchedules = _prodBonusWorkScheduleService.GetByLineID(prodLine.ID); } item.ProdBonusWorkSchedules = _prodBonusWorkScheduleService.GetWithSetupID(ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getLines/{setupID}")] public ActionResult getLines(int setupID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List item = new List(); try { item = _prodBonusLineService.GetLineBySetupId(setupID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("getProdBonusAtten")] public ActionResult getProdBonusAtten(dynamic processItems) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); int setupID = (int)item["setupId"].ToObject(); int lineID = (int)item["lineId"].ToObject(); DateTime date = (DateTime)item["date"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List AttnItems = new List(); try { AttnItems = _prodBonusAttnService.GetBySetupLineDate(setupID, lineID, date); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(AttnItems); } [HttpPost] [Route("getProdBonusAttnEmployeeList")] public ActionResult getProdBonusAttnEmployeeList(dynamic pItem) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(pItem)); DateTime date = (DateTime)item["date"].ToObject(); ProdBonusLine _oProdBonusLine = (ProdBonusLine)item["prodLine"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List _oEmployees = new EmployeeService().Get(EnumEmployeeStatus.Live, (int)currentUser.PayrollTypeID); List _oFinalEmployees = new List(); List _oProdBonusParameters = new List(); List _oProdBonusSupervisors = new List(); List _oDailyAttnProsess = new List(); try { _oProdBonusParameters = _oProdBonusLine.ProdBonusParameters; _oProdBonusSupervisors = _oProdBonusLine.ProdBonusSupervisors; if (_oProdBonusParameters != null && _oProdBonusParameters.Count > 0) { List desigparam = _oProdBonusParameters.Where(o => o.ItemType == EnumBonusItemType.Designation).ToList(); foreach (ProdBonusParameter pbp in _oProdBonusParameters) { List oTempEmployees = null; if (pbp.ItemType == EnumBonusItemType.Department) { oTempEmployees = _oEmployees.FindAll(delegate (Employee e1) { return e1.DepartmentID == pbp.ItemID && e1.DesignationID != 2; }); //Employee other than supervisor } foreach (ProdBonusSupervisor svsr in _oProdBonusSupervisors) { Employee emp = _oEmployees.FirstOrDefault(o => o.ID == svsr.EmployeeID); if (emp != null) { oTempEmployees.Add(emp); } } //else //{ // oTempEmployees = _oEmployees.FindAll(delegate(Employee e1) { return e1.DesignationID == pbp.ItemID; }); //} if (oTempEmployees != null) { foreach (Employee ee in oTempEmployees) _oFinalEmployees.Add(ee); } } //foreach (ProdBonusParameter item in desigparam) //{ // if (_oFinalEmployees != null && _oFinalEmployees.Count > 0) // { // _oFinalEmployees = _oFinalEmployees.Where(o => o.DesignationID != item.ItemID).ToList(); // } //} } string emIds = _oFinalEmployees.Aggregate(new StringBuilder(), (sb, x) => sb.Append(x.ID + ","), sb => sb.ToString().Trim(',')); if (emIds != "") { _oDailyAttnProsess = new DailyAttnProcessService().Get(emIds, date.Date, date.Date.AddHours(23.9)); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(_oFinalEmployees); } [HttpPost] [Route("getProdBonusAttnEmployeeListSwingAndPrinting")] public ActionResult getProdBonusAttnEmployeeListSwingAndPrinting(dynamic pItem) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(pItem)); DateTime date = (DateTime)item["date"].ToObject(); ProdBonusLine _oProdBonusLine = (ProdBonusLine)item["prodLine"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List _oEmployees = new EmployeeService().Get(EnumEmployeeStatus.Live, (int)currentUser.PayrollTypeID); List _oFinalEmployees = new List(); List _oProdBonusParameters = new List(); List _oProdBonusSupervisors = new List(); List _oDailyAttnProsess = new List(); List _oProdBonusAttns = null; try { DateTime? maxDate = _prodBonusAttnService.GetMaxDate(_oProdBonusLine.ProdBonusSetupID, _oProdBonusLine.ID, date); if(maxDate != null) _oProdBonusAttns = _prodBonusAttnService.GetBySetupLineDate(_oProdBonusLine.ProdBonusSetupID, _oProdBonusLine.ID, (DateTime)maxDate); List desigparam = _oProdBonusParameters.Where(o => o.ItemType == EnumBonusItemType.Designation).ToList(); if(_oProdBonusAttns != null && _oProdBonusAttns.Count > 0) { foreach (var pda in _oProdBonusAttns) { Employee emp = _oEmployees.Find(o => o.ID == pda.EmployeeID); if (emp != null) _oFinalEmployees.Add(emp); } } string emIds = _oFinalEmployees.Aggregate(new StringBuilder(), (sb, x) => sb.Append(x.ID + ","), sb => sb.ToString().Trim(',')); if (emIds != "") { _oDailyAttnProsess = new DailyAttnProcessService().Get(emIds, date.Date, date.Date.AddHours(23.9)); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(_oFinalEmployees); } [HttpGet("getByLineID/{lineID}")] public ActionResult getByLineID(int lineID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List item = new List(); try { item = _prodBonusAttnService.GetByLineID(lineID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("saveAllProdBonusAttn")] public ActionResult saveAllProdBonusAttn(dynamic processItems) { var prodBonusAttnItems = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems["prodBonusAttn"])); List oProdBonusAttns = new List(); foreach (var prodBonusAttnItem in prodBonusAttnItems) { ProdBonusAttn oProdBonusAttn = (ProdBonusAttn)prodBonusAttnItem.ToObject(); oProdBonusAttns.Add(oProdBonusAttn); } var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); int setupId = (int)item["setupId"].ToObject(); int scheduleId = (int)item["scheduleId"].ToObject(); DateTime date = (DateTime)item["date"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); //List item = new List(); DataTable dt = null; try { _prodBonusAttnService.Save(oProdBonusAttns, setupId, scheduleId, date); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(dt); } //[HttpGet("getAllLine/{ID}")] //public ActionResult getAllLine(int ID) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // List items = new List(); // //ProdBonusLine prodLine = new ProdBonusLine(); // try // { // items = _prodBonusLineService.GetLines(ID); // //item.ProductionBonusLines = _prodBonusLineService.GetLineBySetupId(ID); // foreach (ProdBonusLine item in items) // { // item.ProdBonusSupervisors = _prodBonusSupervisorService.GetByLineID(item.ID); // items.ProdBonusParameters = _prodBonusParameterService.GetWithSetupID(item.ID); // } // items.ProdBonusParameters = _prodBonusWorkScheduleService.GetWithSetupID(ID); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} [HttpPost] [Route("getProdBonusProcessBySalaryMonth")] public ActionResult getProdBonusProcessBySalaryMonth(dynamic processItems) { var processItem = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime dtpSalaryMonth = (DateTime)processItem["salaryMonthDate"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List items = new List(); try { items = _prodBonusProcessService.Get(GlobalFunctions.LastDateOfMonth(dtpSalaryMonth)); foreach (ProdBonusProcess item in items) { item.ProdBonusProcessEmps = _prodBonusProcessService.GetProdBonusProcessEmps(item.ID); item.ProdBonusProcessItems = _prodBonusProcessService.GetProdBonusProcessItems(item.ID); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("getProdBonusSetupBySalaryMonth")] public ActionResult getProdBonusSetupBySalaryMonth(dynamic processItems) { var processItem = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime dtpSalaryMonth = (DateTime)processItem["salaryMonthDate"].ToObject(); List items = new List(); try { items = _productionBonusSetupService.Get(GlobalFunctions.LastDateOfMonth(dtpSalaryMonth)); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("processProdBonusProcess")] public ActionResult processProdBonusProcess(dynamic processItems) { var prodBonusSetupItems = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems["prodBonusSetup"])); List _oProductionBonusSetups = new List(); foreach (var prodBonusSetupItem in prodBonusSetupItems) { ProductionBonusSetup _oProductionBonusSetup = (ProductionBonusSetup)prodBonusSetupItem.ToObject(); _oProductionBonusSetups.Add(_oProductionBonusSetup); } var pItem = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime dtpSalaryMonth = (DateTime)pItem["salaryMonthDate"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); //int setupID = ConfigurationManager.GetIntValue("bonus", "productionbonussetupid", EnumConfigurationType.Logic); int setupID = 21; ProdBonusProcess _oProdBonusProcess = new ProdBonusProcess(); try { _oProdBonusProcess = _prodBonusProcessService.Process(_oProductionBonusSetups, dtpSalaryMonth, payrollTypeId); _prodBonusProcessService.Save(_oProdBonusProcess); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(_oProdBonusProcess); } [HttpPost] [Route("undoProdBonusProcess")] public ActionResult undoProdBonusProcess(dynamic processItems) { var processItem = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(processItems)); DateTime dtpSalaryMonth = (DateTime)processItem["salaryMonthDate"].ToObject(); try { //ProdBonusProcess oProdBonusPross = new ProdBonusProcess(); //SystemInformation oSystemInformation = new SystemInformation(); //oSystemInformation.CurrentSysInfo = new SystemInformationService().Get(); //DateTime nextPayProcessDate = new SystemInformationService().Get().NextPayProcessDate; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime nextPayProcessDate = currentUser.NextPayProcessDate.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); if (dtpSalaryMonth.Month == nextPayProcessDate.Month && dtpSalaryMonth.Year == nextPayProcessDate.Year) { List oProdBonusProsses = _prodBonusProcessService.Get(GlobalFunctions.LastDateOfMonth(dtpSalaryMonth)); // if (MessageBox.Show("Do you want to Undo Bonus process?", "Bonus Process", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // { if (oProdBonusProsses.Count > 0) { //int setupID = ConfigurationManager.GetIntValue("bonus", "productionbonussetupid", EnumConfigurationType.Logic); int setupID = 21; ADParameter _ADParam = new ADParameterService().Get(setupID, payrollTypeId); _prodBonusProcessService.UndoProcess(oProdBonusProsses, _ADParam, GlobalFunctions.LastDateOfMonth(dtpSalaryMonth)); //MessageBox.Show("Bonus process deleted successfully.", "Undo Bonus Process", MessageBoxButtons.OK, MessageBoxIcon.Information); } //} } else { throw new Exception("Can not undo previous month Production Bonus process."); //MessageBox.Show("Can not undo previous month Production Bonus process.", "Undo Bonus Process", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } //[HttpPost] //[Route("saveProdBonusProcess")] //public ActionResult saveProdBonusProcess(List oProdBonusProcessItems) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // //int setupID = ConfigurationManager.GetIntValue("bonus", "productionbonussetupid", EnumConfigurationType.Logic); // int setupID = 21; // ADParameter oADParam = new ADParameterService().Get(setupID, payrollTypeId); // try // { // _prodBonusProcessService.Save(oProdBonusProcessItems); // new ADParameterService().Save(oADParam); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(); //} #endregion [HttpPost] [Route("savePrbCalculation")] public ActionResult savePrbCalculation(List oPrbItems) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { foreach (PRBCalculation oPRBCalculation in oPrbItems) { oPRBCalculation.CreatedBy = currentUser.UserID; } _prbCalculationService.Save(oPrbItems); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("savePrbCalculations")] public ActionResult savePrbCalculations(dynamic data) { List oPrbItems = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); oPrbItems = item["prbCalculation"].ToObject>(); DateTime prbYear = (DateTime)item["prbYear"].ToObject(); DateTime prbMonth = (DateTime)item["prbMonth"].ToObject(); try { foreach (PRBCalculation oPRBCalculation in oPrbItems) { var monthStart = new DateTime(prbYear.Year, prbMonth.Month, 1); oPRBCalculation.EndDate = monthStart.AddMonths(1).AddDays(-1); // last date of month of selected month and year oPRBCalculation.Year = new DateTime(prbYear.Year, 12, 31); // last day of month of selected year oPRBCalculation.CreatedBy = currentUser.UserID; } _prbCalculationService.Save(oPrbItems, prbMonth, prbYear, currentUser.UserID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("savePrbKpi")] public ActionResult savePrbKpi(PRBKpi prbkpi) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { var lastdayofmonth = DateTime.DaysInMonth(DateTime.Now.Year, prbkpi.PRBMonth.Month); var monthEnd = new DateTime(DateTime.Now.Year, prbkpi.PRBMonth.Month, lastdayofmonth); prbkpi.PRBMonth = monthEnd; _prbKpiService.Save(prbkpi); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost("getPrevPrbByEmployeeIds")] public ActionResult GetPrevPrbByEmployeeIds(dynamic data) { List prbCalcList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int? payrolltypeid = null; if (currentUser.PayrollTypeID != null) payrolltypeid = (int)currentUser.PayrollTypeID; string empIds = (string)item["dataList"].ToObject(); DateTime prbYear = (DateTime)item["prbYear"].ToObject(); DateTime prbMonth = (DateTime)item["prbMonth"].ToObject(); try { prbCalcList = _prbCalculationService.GetByEmpIds(empIds, prbYear, prbMonth); List grades = new GradeService().Get(EnumStatus.Regardless, (int)payrolltypeid); List designations = new DesignationService().Get(EnumStatus.Regardless, (int)payrolltypeid); List departments = new DepartmentService().Get(EnumStatus.Regardless, (int)payrolltypeid); if (prbCalcList.Count > 0) { foreach (var prb in prbCalcList) { if (prb.EmployeeID > 0) { prb.Employee = new Employee(); prb.Employee = new EmployeeService().Get(prb.EmployeeID); // prb.BonusAmount = prb.Employee.BasicSalary; var grd = grades.FirstOrDefault(d => d.ID == prb.Employee.GradeID); if (grd != null) prb.Employee.GradeName = grd.Name; var designation = designations.FirstOrDefault(d => d.ID == prb.Employee.DesignationID); if (designation != null) prb.Employee.DesignationName = designation.Name; var department = departments.FirstOrDefault(d => d.ID == prb.Employee.DepartmentID); if (department != null) prb.Employee.DepartmentName = department.Name; prb.BonusAmountString = string.Format("{0:N2}", prb.BonusAmount); prb.TotalPRBString = string.Format("{0:N2}", prb.TotalPRB); prb.TotalAcheiveString = string.Format("{0:N2}", prb.TotalAcheive); prb.T1AcheiveTemp = prb.TargetT1 * (prb.AcheiveT1 / 100); prb.T2AcheiveTemp = prb.TargetT2 * (prb.AcheiveT2 / 100); prb.T3AcheiveTemp = prb.TargetT3 * (prb.AcheiveT3 / 100); prb.T4AcheiveTemp = prb.TargetT4 * (prb.AcheiveT4 / 100); prb.T5AcheiveTemp = prb.TargetT5 * (prb.AcheiveT5 / 100); prb.T6AcheiveTemp = prb.TargetT6 * (prb.AcheiveT6 / 100); prb.T7AcheiveTemp = prb.TargetT7 * (prb.AcheiveT7 / 100); prb.T8AcheiveTemp = prb.TargetT8 * (prb.AcheiveT8 / 100); prb.T9AcheiveTemp = prb.TargetT9 * (prb.AcheiveT9 / 100); prb.T10AcheiveTemp = prb.TargetT10 * (prb.AcheiveT10 / 100); } } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(prbCalcList); } [HttpGet("getPrbKpi")] public ActionResult GetPrbKpi() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List prbKpiList = new List(); try { prbKpiList = _prbKpiService.GetAll(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(prbKpiList); } [HttpGet("getPrbByMonth/{bonusMonth}")] public ActionResult getPrbByMonth(string bonusMonth) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List prbKpiList = new List(); List temoKpiList = new List(); DateTime dDate = GlobalFunctions.GetApiDefaultDateData(bonusMonth); try { prbKpiList = _prbKpiService.GetAll(); foreach (var item in prbKpiList) { if (item.PRBMonth.Month == dDate.Month) { temoKpiList.Add(item); } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(temoKpiList); } [HttpGet("getKpiByPrbMonth/{bonusMonth}")] public ActionResult getKpiByPrbMonth(string bonusMonth) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List prbKpiList = new List(); DateTime dDate = GlobalFunctions.GetApiDefaultDateData(bonusMonth); try { prbKpiList = _prbKpiService.GetKpiByPrbMonth(dDate); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(prbKpiList); } [HttpGet("savePrbKpiFullYear")] public ActionResult savePrbKpiFullYear() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List prbKpiListJan = new List(); List prbKpiListFullYear = new List(); try { var firstDayOfYear = new DateTime(DateTime.Now.Year, 1, 1); var startDate = new DateTime(DateTime.Now.Year, 2, 1); var endDate = new DateTime(DateTime.Now.Year, 12, 31); int monthsApart = 12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month; var monthCount = Math.Abs(monthsApart) + 1; prbKpiListJan = _prbKpiService.GetKpiByPrbMonth(firstDayOfYear); bool isDataExistForDec = _prbKpiService.IsKpiByPrbMonth(endDate); if (isDataExistForDec) { throw new Exception("Target already set up to december month"); } if (prbKpiListJan != null && prbKpiListJan.Count > 0 && isDataExistForDec == false) { DateTime? prbMonth = null; for (int i = 1; i <= monthCount; i++) { prbMonth = new DateTime(DateTime.Now.Year, i + 1, 1); foreach (var item in prbKpiListJan) { var prbTarget = new PRBKpi(); prbTarget.Serial = item.Serial; prbTarget.KpiName = item.KpiName; prbTarget.PRBMonth = (DateTime)prbMonth; prbTarget.Description = item.Description; prbKpiListFullYear.Add(prbTarget); } } } else { throw new Exception("Please set the target of January Month"); } _prbKpiService.Save(prbKpiListFullYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } private static DataTable ExtractFromExcel(System.IO.Stream fileStream, string sheetName = "") { ImportHelper iHelper = new ImportHelper(); DataSet dDataSet = iHelper.Import(ImportHelper.Formats.Excel, fileStream, true); try { return dDataSet.Tables[0].Copy(); } catch (Exception) { if (string.IsNullOrEmpty(sheetName)) { throw new Exception("No sheet Found in Excel"); } else { throw new Exception("Could not Find sheet with name:" + sheetName); } } } [HttpPost] [Route("uploadPrbCalculation")] public ActionResult uploadPrbCalculation() { _errorOrSuccessList = new List(); // List errorOrSuccessList = new List(); DateTime selectedDate = DateTime.Today; DateTime selectedYear = DateTime.Today; int userid = 0; int payrollTypeid = 0; try { string date = Request.Form["selectedDate"]; string year = Request.Form["selectedYear"]; string userId = Request.Form["userId"]; string payrollTypeId = Request.Form["payrollTypeId"]; if (!string.IsNullOrEmpty(date)) { selectedDate = DateTime.Parse(date); } if (!string.IsNullOrEmpty(year)) { selectedYear = DateTime.Parse(year); } if (!string.IsNullOrEmpty(userId)) { userid = int.Parse(userId); } if (!string.IsNullOrEmpty(payrollTypeId)) { payrollTypeid = int.Parse(payrollTypeId); } var files = Request.Form.Files; foreach (var formFile in files) { _uplodedData = ExtractFromExcel(formFile.OpenReadStream(), "Sheet1"); break; } PRBcalculation(selectedDate, selectedYear, userid, payrollTypeid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(_errorOrSuccessList); } private static void fillPrbData(PRBCalculation prbCal, DataRow oDR, int nRow, DateTime prbMonth) { List kpis = new PRBKpiService().GetAll(); if (prbCal != null) { var kpi = kpis.Find(item => item.KpiName.ToLower().Trim() == Convert.ToString(oDR["KPIName"]).ToLower().Trim() && item.PRBMonth.ToString("MMM").ToLower() == prbMonth.ToString("MMM").ToLower()); if (kpi != null) { if (kpi.Serial.Trim() == "T1") { prbCal.TargetT1 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT1 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT1 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T2") { prbCal.TargetT2 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT2 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT2 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T3") { prbCal.TargetT3 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT3 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT3 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T4") { prbCal.TargetT4 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT4 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT4 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T5") { prbCal.TargetT5 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT5 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT5 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T6") { prbCal.TargetT6 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT6 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT6 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T7") { prbCal.TargetT7 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT7 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT7 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T8") { prbCal.TargetT5 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT5 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT8 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T9") { prbCal.TargetT9 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT9 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT9 = (prbCal.BonusAmount * acheiveTemp) / 100; } if (kpi.Serial.Trim() == "T10") { prbCal.TargetT10 = Convert.ToDouble(oDR["Target"]); prbCal.AcheiveT10 = Convert.ToDouble(oDR["Achieve"]); double acheiveTemp = Convert.ToDouble(oDR["Target"]) * (Convert.ToDouble(oDR["Achieve"]) / 100); prbCal.TotalAcheive += acheiveTemp; prbCal.AmountT10 = (prbCal.BonusAmount * acheiveTemp) / 100; } } else { _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee ID", nRow, "Target not found: " + oDR["KPIName"].ToString())); } } } public void PRBcalculation(DateTime selectedDate, DateTime selectedYear, int userId, int payrollId) { try { //CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int nRow = 0; List oPrbCalculations = new List(); List employees = new EmployeeService().GetAllEmps(payrollId); // should be changed List grades = new GradeService().Get(EnumStatus.Active, payrollId); Employee tempEmployee = null; try { foreach (DataRow oDR in _uplodedData.Rows) { nRow = nRow + 1; tempEmployee = employees.Find(item => item.EmployeeNo.ToLower().Trim() == Convert.ToString(oDR["EmployeeNo"]).ToLower().Trim()); var IsExist = oPrbCalculations.Where(x => x.EmployeeID == tempEmployee.ID).Any(); PRBCalculation prbCal = new PRBCalculation(); if (tempEmployee != null && IsExist == false) { prbCal.Employee = new Employee(); prbCal.EmployeeID = tempEmployee.ID; prbCal.Employee.GradeID = tempEmployee.GradeID; prbCal.Employee.GradeName = grades?.Where(x => x.ID == tempEmployee.GradeID)?.FirstOrDefault().Code; //DateTime firstDay = new DateTime(DateTime.Now.Year, 1, 1); //DateTime lastDay = new DateTime(DateTime.Now.Year, 12, 31); DateTime firstDay = new DateTime(selectedYear.Year, 1, 1); DateTime lastDay = new DateTime(selectedYear.Year, 12, 31); int whole_year_in_days = (lastDay - firstDay).Days + 1; //365 days //int whole_year_in_days = 365; //365 days if (firstDay > tempEmployee.JoiningDate) { prbCal.Employee.JoiningDate = firstDay; } var monthStart = new DateTime(selectedYear.Year, selectedDate.Month, 1); var monthEnd = monthStart.AddMonths(1).AddDays(-1); // last date of month of selected month and year prbCal.EndDate = monthEnd;// last date of month of selected month and year prbCal.Year = lastDay; // last day of Selected Year int number_of_Days = (prbCal.EndDate - prbCal.Employee.JoiningDate).Days + 1; var houseRent = tempEmployee.BasicSalary * (60.00 / 100.00); var conveyance = tempEmployee.BasicSalary * (10.00 / 100.00); var special = tempEmployee.BasicSalary * (10.00 / 100.00); var grossSalary = tempEmployee.BasicSalary + houseRent + conveyance + special; if (number_of_Days >= whole_year_in_days) { prbCal.NoOFDays = whole_year_in_days; } else { prbCal.NoOFDays = number_of_Days; } var annualBaseSalary = (grossSalary * 12) + tempEmployee.BasicSalary; // 12 gross + 1 basic prbCal.AnnualBasicSalary = annualBaseSalary; var bonusTarget = (annualBaseSalary * 20) / 100; // 20% target in excel prbCal.ProrataCal = (bonusTarget / whole_year_in_days) * prbCal.NoOFDays; prbCal.BonusAmount = prbCal.ProrataCal; fillPrbData(prbCal, oDR, nRow, selectedDate); //prbCal.TotalPRB = prbCal.BonusAmount * (prbCal.TotalAcheive / 100); prbCal.TotalPRB = prbCal.AmountT1 + prbCal.AmountT2 + prbCal.AmountT3 + prbCal.AmountT4 + prbCal.AmountT5 + prbCal.AmountT6 + prbCal.AmountT7 + prbCal.AmountT8 + prbCal.AmountT9 + prbCal.AmountT10; prbCal.CreatedBy = userId; prbCal.PRBStatus = EnumPRBStatus.Draft; oPrbCalculations.Add(prbCal); } else if (tempEmployee != null && IsExist == true) { var existingPrbCal = oPrbCalculations.Find(x => x.EmployeeID == tempEmployee.ID); prbCal = existingPrbCal; prbCal.PRBStatus = EnumPRBStatus.Draft; fillPrbData(prbCal, oDR, nRow, selectedDate); // prbCal.TotalPRB = prbCal.BonusAmount * (prbCal.TotalAcheive / 100); prbCal.TotalPRB = prbCal.AmountT1 + prbCal.AmountT2 + prbCal.AmountT3 + prbCal.AmountT4 + prbCal.AmountT5 + prbCal.AmountT6 + prbCal.AmountT7 + prbCal.AmountT8 + prbCal.AmountT9 + prbCal.AmountT10; } else { _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee ID", nRow, "Employee ID not found: " + oDR["Employee-ID"].ToString())); } } } catch (Exception ex) { throw new ServiceException("Error occured on row:" + nRow + " Reason:" + ex.Message); } if (_errorOrSuccessList.Count == 0 && oPrbCalculations.Count > 0) { //total acheive count //foreach (PRBCalculation prbCal in oPrbCalculations) //{ // double totalAchiveTemp = 0.0; // if (prbCal.Employee.GradeName != null) // { // string grade = prbCal.Employee.GradeName; // if (grade.Trim().ToLower() == "a" || grade.Trim().ToLower() == "b1" || grade.Trim().ToLower() == "b2" || grade.Trim().ToLower() == "b3" // || grade.Trim().ToLower() == "n1") // { // if (prbCal.TotalAcheive > 100) // { // var acheiveCount = (double)(prbCal.TotalAcheive - 100); // if (acheiveCount > 0) // { // double achiveForManager = 100 + (3 * acheiveCount); // totalAchiveTemp = achiveForManager; // } // } // else if (prbCal.TotalAcheive > 90 && prbCal.TotalAcheive < 100) // { // var acheiveCount = (100 - prbCal.TotalAcheive); // if (acheiveCount > 0) // { // var achiveForManager = (double)(100 - (2 * acheiveCount)); // totalAchiveTemp = achiveForManager; // } // } // else if (prbCal.TotalAcheive < 90) // { // totalAchiveTemp = 0; // } // prbCal.TotalAcheive = totalAchiveTemp; // prbCal.TotalPRB = prbCal.BonusAmount * (prbCal.TotalAcheive / 100); // } // else if (grade.Trim().ToLower() == "c" || grade.Trim().ToLower() == "c1" || grade.Trim().ToLower() == "d" || grade.Trim().ToLower() == "e" // || grade.Trim().ToLower() == "f1" || grade.Trim().ToLower() == "f2" || grade.Trim().ToLower() == "g1" || grade.Trim().ToLower() == "g2" // || grade.Trim().ToLower() == "h1" || grade.Trim().ToLower() == "h2" || grade.Trim().ToLower() == "h3" // || grade.Trim().ToLower() == "i" || grade.Trim().ToLower() == "j") // { //stuff grade // if (prbCal.TotalAcheive > 100) // { // var acheiveCount = prbCal.TotalAcheive - 100; // if (acheiveCount > 0) // { // var achiveForStaff = (double)(100 + (2 * acheiveCount)); // totalAchiveTemp = achiveForStaff; // } // } // else if (prbCal.TotalAcheive < 100) // { // var acheiveCount = (100 - prbCal.TotalAcheive); // if (acheiveCount > 0) // { // var achiveForStaff = 100 - (1 * acheiveCount); // prbCal.TotalAcheive = achiveForStaff; // } // } // prbCal.TotalAcheive = totalAchiveTemp; // prbCal.TotalPRB = prbCal.BonusAmount * (prbCal.TotalAcheive / 100); // } // } //} new PRBCalculationService().Save(oPrbCalculations, selectedDate, selectedYear, userId); } else if (_errorOrSuccessList.Count > 0) { string message = ""; foreach (var item in _errorOrSuccessList) { message += " Error occured on row: " + item.RowNo + " Column Name: " + item.ColumName + " : " + item.Message +"; "; } throw new Exception(message); } } catch (Exception ex) { throw new Exception(ex.Message); } } [HttpGet("getprbbonusbytranid/{tranid}")] public ActionResult getPrbBonusbyTranid(int tranid) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); WFMovementTran wfTran = new WFMovementTran(); // PRBCalculation prbCalculation = null; List prbCalculations = null; List prbcalculationReports = new List(); var grades = _gradeService.Get(EnumStatus.Active, (int)currentUser.PayrollTypeID); try { wfTran = _wfMovementTranService.Get(tranid); if (wfTran != null) { var batchId = wfTran.ObjectID; if (batchId > 0) { prbCalculations = new List(); prbCalculations = _prbCalculationService.GetByBatchId(batchId); foreach(var prbCalculation in prbCalculations) { prbCalculation.Employee = _empService.Get(prbCalculation.EmployeeID); var grade = grades.Find(x => x.ID == prbCalculation.Employee.GradeID).Name; prbCalculation.Employee.GradeName = grade; var prbcalculationReport = new PRBCalculationReport(); prbcalculationReport.PrbKpiList = _prbKpiService.GetKpiByPrbMonth(prbCalculation.EndDate); prbcalculationReport.ID = prbCalculation.ID; prbcalculationReport.Employee = prbCalculation.Employee; prbcalculationReport.BonusAmount = string.Format("{0:N2}", prbCalculation.BonusAmount); prbcalculationReport.TargetT1 = (double)prbCalculation.TargetT1; prbcalculationReport.TargetT2 = (double)prbCalculation.TargetT2; prbcalculationReport.TargetT3 = (double)prbCalculation.TargetT3; prbcalculationReport.TargetT4 = (double)prbCalculation.TargetT4; prbcalculationReport.TargetT5 = (double)prbCalculation.TargetT5; prbcalculationReport.TargetT6 = (double)prbCalculation.TargetT6; prbcalculationReport.TargetT7 = (double)prbCalculation.TargetT7; prbcalculationReport.TargetT8 = (double)prbCalculation.TargetT8; prbcalculationReport.TargetT9 = (double)prbCalculation.TargetT9; prbcalculationReport.TargetT10 = (double)prbCalculation.TargetT10; prbcalculationReport.AcheiveT1 = (double)prbCalculation.AcheiveT1; prbcalculationReport.AcheiveT2 = (double)prbCalculation.AcheiveT2; prbcalculationReport.AcheiveT3 = (double)prbCalculation.AcheiveT3; prbcalculationReport.AcheiveT4 = (double)prbCalculation.AcheiveT4; prbcalculationReport.AcheiveT5 = (double)prbCalculation.AcheiveT5; prbcalculationReport.AcheiveT6 = (double)prbCalculation.AcheiveT6; prbcalculationReport.AcheiveT7 = (double)prbCalculation.AcheiveT7; prbcalculationReport.AcheiveT8 = (double)prbCalculation.AcheiveT8; prbcalculationReport.AcheiveT9 = (double)prbCalculation.AcheiveT9; prbcalculationReport.AcheiveT10 = (double)prbCalculation.AcheiveT10; prbcalculationReport.AmountT1 = string.Format("{0:N2}", prbCalculation.AmountT1); prbcalculationReport.AmountT2 = string.Format("{0:N2}", prbCalculation.AmountT2); prbcalculationReport.AmountT3 = string.Format("{0:N2}", prbCalculation.AmountT3); prbcalculationReport.AmountT4 = string.Format("{0:N2}", prbCalculation.AmountT4); prbcalculationReport.AmountT5 = string.Format("{0:N2}", prbCalculation.AmountT5); prbcalculationReport.AmountT6 = string.Format("{0:N2}", prbCalculation.AmountT6); prbcalculationReport.AmountT7 = string.Format("{0:N2}", prbCalculation.AmountT7); prbcalculationReport.AmountT8 = string.Format("{0:N2}", prbCalculation.AmountT8); prbcalculationReport.AmountT9 = string.Format("{0:N2}", prbCalculation.AmountT9); prbcalculationReport.AmountT10 = string.Format("{0:N2}", prbCalculation.AmountT10); prbcalculationReport.TotalAcheive = string.Format("{0:N2}", prbCalculation.TotalAcheive); prbcalculationReport.TotalPRBString = string.Format("{0:N2}", prbCalculation.TotalPRB); prbcalculationReport.AnnualBasicSalary = string.Format("{0:N2}", prbCalculation.AnnualBasicSalary); prbcalculationReport.NoOFDays = prbCalculation.NoOFDays; prbcalculationReport.JoiningDate = prbCalculation.Employee.JoiningDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); prbcalculationReport.EndDate = prbCalculation.EndDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); prbcalculationReports.Add(prbcalculationReport); } } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(prbcalculationReports); } [HttpPost] [Route("ApprovePRB")] public ActionResult ApprovePRB(WFMovementTran _wftran) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); WFMovementTran wfTran = new WFMovementTran(); // wfTran.FromEmployeeID = (int)currentUser.EmployeeID; var remarks = _wftran.Remarks; try { wfTran = _wfMovementTranService.Get(_wftran.ID); wfTran.Remarks = remarks; wfTran.UserID = currentUser.UserID; wfTran.FromEmployeeID = (int)currentUser.EmployeeID; _prbCalculationService.ApprovePRBBonus(wfTran); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("RejectPRB")] public ActionResult RejectPRB(WFMovementTran _wftran) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); WFMovementTran wfTran = new WFMovementTran(); var remarks = _wftran.Remarks; try { wfTran = _wfMovementTranService.Get(_wftran.ID); wfTran.Remarks = remarks; wfTran.UserID = currentUser.UserID; wfTran.FromEmployeeID = (int)currentUser.EmployeeID; _prbCalculationService.RejectPRBBonus(wfTran); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost("submitForPrbApproval")] public ActionResult submitForPrbApproval(dynamic data) { List prbCalcList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime prbYear = (DateTime)item["prbYear"].ToObject(); DateTime prbMonth = (DateTime)item["prbMonth"].ToObject(); int getYear = (prbYear.Year) % 100; //last two digit int getMonth = prbMonth.Month; var builder = new StringBuilder(); int batchId = Convert.ToInt32(builder.Append(getMonth).Append(getYear).ToString()); try { prbCalcList = _prbCalculationService.GetByBatchId(batchId); List employees = _empService.GetAllLive(); // all live employee if (prbCalcList.Count == employees.Count) { _prbCalculationService.InitiatePRBCalculationWorkFlow(batchId, currentUser.UserID, prbCalcList[0].EmployeeID); //employeID should be changed } else { throw new Exception("Pleaase calculate for all employee"); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(prbCalcList); } [HttpPost] [Route("getPrbAmountOfCurrentMonth")] public ActionResult GetPrbAmountOfCurrentMonth(WFMovementTran _wftran) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); WFMovementTran wfTran = new WFMovementTran(); DataTable olist = null; try { wfTran = _wfMovementTranService.Get(_wftran.ID); olist = _prbCalculationService.GetPrbAmountOfCurrentMonth(wfTran.ObjectID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpPost("checkStatus")] public ActionResult checkStatus(dynamic data) { List prbCalcList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime prbYear = (DateTime)item["prbYear"].ToObject(); DateTime prbMonth = (DateTime)item["prbMonth"].ToObject(); int getYear = (prbYear.Year) % 100; //last two digit int getMonth = prbMonth.Month; var builder = new StringBuilder(); int batchId = Convert.ToInt32(builder.Append(getMonth).Append(getYear).ToString()); bool isSubmitForApproval = false; try { List employees = _empService.GetAllLive(); prbCalcList = _prbCalculationService.GetByBatchId(batchId); if(prbCalcList.Count > 0 && prbCalcList.Count == employees.Count) { var isExit= prbCalcList.Where(y => y.PRBStatus == EnumPRBStatus.Draft || y.PRBStatus == EnumPRBStatus.None).Any(); if(!isExit) { isSubmitForApproval = true; } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(isSubmitForApproval); } [HttpPost("getReportbyBatchId")] public ActionResult GetReportbyBatchId(dynamic data) { List prbCalcList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime prbYear = (DateTime)item["prbYear"].ToObject(); DateTime prbMonth = (DateTime)item["prbMonth"].ToObject(); int getYear = (prbYear.Year) % 100; //last two digit int getMonth = prbMonth.Month; var builder = new StringBuilder(); int batchId = Convert.ToInt32(builder.Append(getMonth).Append(getYear).ToString()); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List prbcalculationReports = new List(); try { var grades = _gradeService.Get(EnumStatus.Active, (int)currentUser.PayrollTypeID); prbCalcList = _prbCalculationService.GetByBatchId(batchId); if(prbCalcList != null && prbCalcList.Count > 0) { foreach (var prbCalculation in prbCalcList) { prbCalculation.Employee = _empService.Get(prbCalculation.EmployeeID); var grade = grades.Find(x => x.ID == prbCalculation.Employee.GradeID).Name; prbCalculation.Employee.GradeName = grade; var prbcalculationReport = new PRBCalculationReport(); prbcalculationReport.PrbKpiList = _prbKpiService.GetKpiByPrbMonth(prbCalculation.EndDate); prbcalculationReport.ID = prbCalculation.ID; prbcalculationReport.Employee = prbCalculation.Employee; prbcalculationReport.BonusAmount = string.Format("{0:N2}", prbCalculation.BonusAmount); prbcalculationReport.TargetT1 = (double)prbCalculation.TargetT1; prbcalculationReport.TargetT2 = (double)prbCalculation.TargetT2; prbcalculationReport.TargetT3 = (double)prbCalculation.TargetT3; prbcalculationReport.TargetT4 = (double)prbCalculation.TargetT4; prbcalculationReport.TargetT5 = (double)prbCalculation.TargetT5; prbcalculationReport.TargetT6 = (double)prbCalculation.TargetT6; prbcalculationReport.TargetT7 = (double)prbCalculation.TargetT7; prbcalculationReport.TargetT8 = (double)prbCalculation.TargetT8; prbcalculationReport.TargetT9 = (double)prbCalculation.TargetT9; prbcalculationReport.TargetT10 = (double)prbCalculation.TargetT10; prbcalculationReport.AcheiveT1 = (double)prbCalculation.AcheiveT1; prbcalculationReport.AcheiveT2 = (double)prbCalculation.AcheiveT2; prbcalculationReport.AcheiveT3 = (double)prbCalculation.AcheiveT3; prbcalculationReport.AcheiveT4 = (double)prbCalculation.AcheiveT4; prbcalculationReport.AcheiveT5 = (double)prbCalculation.AcheiveT5; prbcalculationReport.AcheiveT6 = (double)prbCalculation.AcheiveT6; prbcalculationReport.AcheiveT7 = (double)prbCalculation.AcheiveT7; prbcalculationReport.AcheiveT8 = (double)prbCalculation.AcheiveT8; prbcalculationReport.AcheiveT9 = (double)prbCalculation.AcheiveT9; prbcalculationReport.AcheiveT10 = (double)prbCalculation.AcheiveT10; prbcalculationReport.AmountT1 = string.Format("{0:N2}", prbCalculation.AmountT1); prbcalculationReport.AmountT2 = string.Format("{0:N2}", prbCalculation.AmountT2); prbcalculationReport.AmountT3 = string.Format("{0:N2}", prbCalculation.AmountT3); prbcalculationReport.AmountT4 = string.Format("{0:N2}", prbCalculation.AmountT4); prbcalculationReport.AmountT5 = string.Format("{0:N2}", prbCalculation.AmountT5); prbcalculationReport.AmountT6 = string.Format("{0:N2}", prbCalculation.AmountT6); prbcalculationReport.AmountT7 = string.Format("{0:N2}", prbCalculation.AmountT7); prbcalculationReport.AmountT8 = string.Format("{0:N2}", prbCalculation.AmountT8); prbcalculationReport.AmountT9 = string.Format("{0:N2}", prbCalculation.AmountT9); prbcalculationReport.AmountT10 = string.Format("{0:N2}", prbCalculation.AmountT10); prbcalculationReport.TotalAcheive = string.Format("{0:N2}", prbCalculation.TotalAcheive); prbcalculationReport.TotalPRBString = string.Format("{0:N2}", prbCalculation.TotalPRB); prbcalculationReport.AnnualBasicSalary = string.Format("{0:N2}", prbCalculation.AnnualBasicSalary); prbcalculationReport.NoOFDays = prbCalculation.NoOFDays; prbcalculationReport.JoiningDate = prbCalculation.Employee.JoiningDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); prbcalculationReport.EndDate = prbCalculation.EndDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); prbcalculationReports.Add(prbcalculationReport); } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(prbcalculationReports); } } }