public void UpdateGM([FromBody] JObject Data) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); tblApprove Ap = header.GetAllApprove().Where(a => a.EvaID == Convert.ToInt32(Data["EvaID"].ToString())).OrderByDescending(a => a.ID).FirstOrDefault(); tblApproveStatus Aps = header.GetApproveStatus().Where(a => a.ApproveID == Ap.ID && a.FlowOrder == 3).FirstOrDefault(); tblEmployee emp = header.getEmployees().Where(a => a.EmployeeNo.Trim() == Data["EmployeeNo"].ToString().Trim()).FirstOrDefault(); header.UpdateGM(Aps.ID, emp.EmployeeNo.Trim(), emp.EmployeeFirstName + " " + emp.EmployeeLastName); }
public List <JObject> ApproveHistory(string EmpID) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); // var header = ServiceContainer.GetService<PesWeb.Service.Modules.EvaManage>(); List <tblApprove> app = header.GetAllApprove(); List <tblApproveStatus> ApS = header.GetApproveStatus().Where(a => a.EmployeeNO == EmpID).OrderByDescending(a => a.ID).ToList(); List <tblApprove> Ap = new List <tblApprove>(); List <tblEvaluation> ListEva = header.GetAllEvaluation().ToList(); List <tblFlowMaster> ListFlow = header.getAllFlow(); foreach (tblApproveStatus o in ApS) { tblApprove Approve = app.Where(a => a.ID == o.ApproveID).FirstOrDefault(); if (Approve != null && ListEva.Where(a => a.Eva_ID == Approve.EvaID).ToList().Count == 1) { Ap.Add(Approve); } } List <tblEmployee> emp = header.getEmployees(); List <JObject> ApObject = new List <JObject>(); Ap.ForEach(a => { JObject tmp = new JObject(); tmp["ApproverID"] = a.ApproverID; tmp["ApproveState"] = a.ApproveState; tmp["EvaID"] = a.EvaID; tmp["GM"] = a.GM; tmp["HR"] = a.HR; tmp["ID"] = a.ID; tmp["Name"] = a.Name; tmp["PM"] = a.PM; tmp["Position"] = a.Position; tmp["PositionID"] = a.PositionID; tmp["ProjectCode"] = a.ProjectCode; tmp["Role"] = a.Role; tmp["ST"] = a.ST; tblApproveStatus ApSt = ApS.Where(b => b.ApproveID == a.ID && b.Status != 0).OrderByDescending(b => b.ID).FirstOrDefault(); tblEvaluation eva = ListEva.Where(b => b.Eva_ID == a.EvaID).FirstOrDefault(); tmp["Date"] = (ApSt != null)? ApSt.ApproveDate.ToString().Substring(0, 9).Replace("-", "/") + " " + ((ApSt.ApproveDate.ToString().ElementAt(11) == ':') ? '0' + ApSt.ApproveDate.ToString().Substring(10, 4).Replace("-", "/") : ApSt.ApproveDate.ToString().Substring(10, 5).Replace("-", "/")) : eva.StartEvaDate.ToString().Substring(0, 9).Replace("-", "/") + " " + ((eva.StartEvaDate.ToString().ElementAt(11) == ':')?'0' + eva.StartEvaDate.ToString().Substring(10, 4).Replace("-", "/"): eva.StartEvaDate.ToString().Substring(10, 5).Replace("-", "/")); tblEmployee empTemp = emp.Where(b => b.EmployeeNo.Replace(" ", "") == a.EmployeeNo).FirstOrDefault(); tmp["name_language"] = JsonConvert.DeserializeObject <JObject> ("{\"EN\":\"" + empTemp.EmployeeFirstName + " " + empTemp.EmployeeLastName + "\",\"TH\":\"" + empTemp.EmployeeFirstNameThai + " " + empTemp.EmployeeLastNameThai + "\"}"); ApObject.Add(tmp); }); return(ApObject); }
public void ApproveState([FromBody] JObject Data) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); // var header = ServiceContainer.GetService<PesWeb.Service.Modules.EvaManage>(); tblApprove AllAp = header.GetAllApprove().Where(a => a.EvaID == Convert.ToInt32(Data["EvaID"].ToString())).OrderByDescending(a => a.ID).FirstOrDefault(); tblApproveStatus ApS = header.GetApproveStatus().Where(a => ((a.EmployeeNO != null)?a.EmployeeNO.Trim():a.EmployeeNO) == Data["EmpID"].ToString() && a.ApproveID == AllAp.ID).OrderByDescending(a => a.ID).FirstOrDefault(); ApS.Status = 1;//Convert.ToInt32(Data["Status"].ToString()); string type = ""; if (ApS.FlowOrder == 1) { AllAp.ST = 1; type = "Project Manager"; } else if (ApS.FlowOrder == 2) { type = "Staff"; AllAp.PM = 1; //header.updateEvaluationStatus(Convert.ToInt32(Data["EvaID"].ToString()), 3); } else if (ApS.FlowOrder == 3) { AllAp.GM = 1; type = "Group Manager"; } else if (ApS.FlowOrder == 4) { AllAp.HR = 1; type = "Human Resource"; header.updateEvaluationStatus(Convert.ToInt32(Data["EvaID"].ToString()), 3); } if (Convert.ToInt32(Data["Status"].ToString()) == 0) { ApS.Status = -1; } header.UpdateApproveData(AllAp); header.UpdateApproveData(ApS); insertLog(AllAp.Name, Data["EmpID"].ToString(), type + " Approve EvaID : " + Data["EvaID"].ToString()); }
public void UpdateApproveData(tblApproveStatus aps) { PSESEntities db = new PSESEntities(); db.SP_UpdateAprroveData(aps.Status, aps.ID); }
public void insertApproveStatus(tblApproveStatus aps) { PSESEntities db = new PSESEntities(); db.SP_InsertApproveFlow(aps.Status, aps.FlowOrder, aps.ApproveID, aps.Comment, aps.Name, aps.EmployeeNO); }
public HttpResponseMessage InsertEva([FromBody] JObject Data) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); var header2 = ServiceContainer.GetService <PesWeb.Service.Modules.HeaderManage>(); List <tblEvaluation> evaAll = new List <tblEvaluation>(); if (evaAll.Count == 0) { int isAdd = 0; string name = ""; tblProjectMember proj = new tblProjectMember(); if (Data["EmployeeNO"].ToString().Length > 10) { isAdd = 1; List <string> nme = Data["EmployeeNO"].ToString().Split('-').ToList(); name = nme[1].Trim(); tblPart2Master role = header.getPart2Data().Where(a => a.Function.Trim() == Data["Position"].ToString().Trim()).FirstOrDefault(); tblProject project = header.getProject().Where(a => a.ProjectNameAlias.Trim() == Data["ProjectNO"].ToString().Trim()).FirstOrDefault(); if (project != null) { Data["ProjectNO"] = project.CustomerCompanyAlias + "-" + project.ProjectNameAlias; } proj.Part2ID = role.Part2ID; Data["EmployeeNO"] = Data["EmployeeNO"].ToString().Split('-')[0].Trim(); } else { proj = header.getProjectMember().Where(a => a.ProjectID == Data["ProjectNO"].ToString()).Where(a => a.StaffID == Data["EmployeeNO"].ToString()).FirstOrDefault(); } header.GetAllEvaluation().Where(a => a.EvaluatorNO == Data["EvaluatorNO"].ToString() && a.EmployeeNO == Data["EmployeeNO"].ToString() && a.ProjectNO == Data["ProjectNO"].ToString() && a.PeriodID == Convert.ToInt32(Data["PeriodID"].ToString())).ToList(); tblEvaluation eva = new tblEvaluation(); Period p = header.GetPeriod().Where(a => a.Period_Id == Convert.ToInt32(Data["PeriodID"].ToString())).FirstOrDefault(); eva.EmployeeNO = Data["EmployeeNO"].ToString(); eva.EvaluatorNO = Data["EvaluatorNO"].ToString(); //eva.Job_ID = (isAdd==1)? Data["ProjectNO"].ToString().Split(':') eva.Job_ID = proj.Part2ID; eva.PeriodID = p.Period_Id; eva.period = p.StartDate.ToString().Substring(3, 7); eva.ProjectNO = Data["ProjectNO"].ToString(); eva.StartEvaDate = Convert.ToDateTime(Data["StartDate"].ToString()); eva.FinishEvaDate = Convert.ToDateTime(Data["FinishDate"].ToString()); tblProject pj = new tblProject(); if (isAdd == 0) { pj = header.getProject().Where(a => a.ProjectID == Data["ProjectNO"].ToString()).FirstOrDefault(); } eva.ProjectCode = (isAdd == 1) ? Data["ProjectNO"].ToString() : pj.CustomerCompanyAlias + " " + pj.ProjectNameAlias; SP_InsertEvaluation_Result evaid = header.InsertEvaData(eva); int eva_ID = evaid.Eva_ID; List <tblHeaderJob> hj = header2.getAllHeaderJob().Where(a => a.PositionNo == proj.Part2ID).ToList(); List <tblHeader> Ans = new List <tblHeader>(); List <tblScore> sc = header.GetAllScore(); List <SP_GetHeaderByPosition_Result> GetHeader = header2.getHeaderByPosition(proj.Part2ID, eva_ID).OrderBy(a => a.H_ID).ToList(); List <tblHeader> hd = header2.GetAllHeader().ToList(); tblHeader H_test = new tblHeader(); H_test.H_ID = 0; // if (GetHeader.Count - GetHeader.Where(a => a.point).ToList().Count < FinalHeader(H_test, hd).ToList().Count) foreach (tblHeaderJob tmpHJ in hj) { foreach (tblHeader hd2 in hd.Where(a => a.H_ID == tmpHJ.H1_ID)) { foreach (tblHeader hd3 in FinalHeader(hd2, hd)) { if (sc.Where(a => a.Eva_ID == eva_ID && a.H3_ID == hd3.H_ID).ToList().Count == 0) { //if (Ans.Where(a => a.H_ID == hd3.H_ID).ToList().Count == 0) Ans.Add(hd3); } } } } foreach (tblHeader h in Ans) { header.InsertSCORE(eva_ID, h.H_ID); } List <tblEmployee> emp = header.getEmployees(); int num = header.GetAllApprove().Where(a => a.EvaID == eva_ID).ToList().Count; if (num == 0) { tblApprove ap = new tblApprove(); ap.EvaID = eva_ID; ap.PositionID = header.getEmployees().Where(a => a.EmployeeNo.Replace(" ", "") == Data["EmployeeNO"].ToString().Replace(" ", "")).FirstOrDefault().PositionNo; ap.Position = header.getPosition().Where(a => a.PositionNo == ap.PositionID).FirstOrDefault().PositionName; tblProjectMember pm = header.getProjectMember().Where(a => a.StaffID.Replace(" ", "") == Data["EmployeeNO"].ToString().Replace(" ", "") && a.ProjectID == Data["ProjectNO"].ToString()).FirstOrDefault(); string role = (isAdd == 1)? Data["Position"].ToString(): header.getPart2Data().Where(a => a.Part2ID == pm.Part2ID).FirstOrDefault().Function; if (isAdd == 0) { name = pm.StaffName; } ap.Role = role; tblEmployee emptemp = emp.Where(a => a.EmployeeNo.Trim() == Data["EmployeeNO"].ToString().Trim()).FirstOrDefault(); ap.Name = (emptemp != null) ? emptemp.EmployeeFirstName + " " + emptemp.EmployeeLastName : ""; //tblProject pj = header.getProject().Where(a => a.ProjectID == Data["ProjectNO"].ToString()).FirstOrDefault(); ap.ProjectCode = eva.ProjectCode; ap.EmployeeNo = Data["EmployeeNO"].ToString().Replace(" ", ""); int pID = header.insertApprove(ap).ID; List <tblFlowMaster> AllFlow = header.getAllFlow(); foreach (tblFlowMaster a in AllFlow) { tblApproveStatus tmp = new tblApproveStatus(); tmp.Comment = ""; tmp.Status = 0; tmp.FlowOrder = a.Flow; if (a.CodeName == "PM") { tblEmployee emp2 = emp.Where(t => t.EmployeeNo.Replace(" ", "") == Data["EvaluatorNO"].ToString().Replace(" ", "")).FirstOrDefault(); tmp.Name = emp2.EmployeeFirstName + " " + emp2.EmployeeLastName; tmp.EmployeeNO = emp2.EmployeeNo; // tmp.Status = 1; } else if (a.CodeName == "ST") { tmp.Name = name; tmp.EmployeeNO = Data["EmployeeNO"].ToString().Replace(" ", ""); } else if (a.CodeName == "HR") { tblEmployee emp2 = emp.Where(t => t.PositionNo == 23).FirstOrDefault(); tmp.Name = emp2.EmployeeFirstName + " " + emp2.EmployeeLastName; tmp.EmployeeNO = emp2.EmployeeNo; } else if (a.CodeName == "GM") { int organNo = (int)emp.Where(s => s.EmployeeNo.Replace(" ", "") == Data["EmployeeNO"].ToString().Replace(" ", "")).FirstOrDefault().OrganizationNo; List <tblEmployeeOrganization> emO = header.getEmployeeOrganization().Where(t => t.OrganizationNo == organNo && t.PositionNo == 21).ToList(); if (emO.Count != 1) { tmp.Name = ""; tmp.EmployeeNO = ""; } else { tblEmployee emp2 = emp.Where(t => t.EmployeeNo.Replace(" ", "") == emO.FirstOrDefault().EmployeeNo).FirstOrDefault(); if (emp2 != null) { tmp.Name = emp2.EmployeeFirstName + " " + emp2.EmployeeLastName; tmp.EmployeeNO = emp2.EmployeeNo; } } } tmp.ApproveID = pID; header.insertApproveStatus(tmp); } } tblEmployee empLog = emp.Where(t => t.EmployeeNo.Replace(" ", "") == Data["EvaluatorNO"].ToString().Replace(" ", "")).FirstOrDefault(); insertLog(empLog.EmployeeFirstName + " " + empLog.EmployeeLastName, empLog.EmployeeNo, "new evaluation : " + eva_ID); return(Request.CreateResponse(HttpStatusCode.OK)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public List <JObject> getEvaData(string EvaluatorID) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); List <SP_GetEvaListByEvaluatorID_Result> evalist = header.getEvaListByEvaluatorID(EvaluatorID).Where(a => a.EvaStatus != 3).OrderByDescending(a => a.Eva_ID).ToList(); List <JObject> Jeva = new List <JObject>(); List <tblEmployee> emp = header.getEmployees(); List <tblApprove> ap = header.GetAllApprove(); List <tblProject> pr = header.getProject(); List <tblApproveStatus> ApS = header.GetApproveStatus(); evalist.ForEach(a => { JObject tmp = new JObject(); tblApprove t = ap.Where(x => x.EvaID == a.Eva_ID).FirstOrDefault(); tmp["ApproveStat"] = (t != null) ? t.ApproveState : 0; if (a.ProjectCode != null && a.ProjectCode.Trim().Length > 0) { tblProject tt = pr.Where(x => x.ProjectNameAlias.Trim() == ((a.ProjectCode.Contains('-') ? a.ProjectCode.Trim().Split('-')[1] : a.ProjectCode))).FirstOrDefault(); tmp["CustomerCompanyAlias"] = (a.ProjectCode.Contains('-') ? a.ProjectCode.Trim().Split('-')[0] : ""); } tblApproveStatus ApSt = ApS.Where(x => x.ApproveID == t.ID && x.Status != 0).OrderByDescending(x => x.ApproveID).FirstOrDefault(); tmp["EmployeeFirstName"] = a.EmployeeFirstName; tmp["EmployeeLastName"] = a.EmployeeLastName; tmp["EvaluatorFirstName"] = a.EvaluatorFirstName; tmp["EvaluatorLastName"] = a.EvaluatorLastName; tmp["EvaStatus"] = a.EvaStatus; tmp["EvaTerm"] = a.EvaTerm; tmp["Eva_ID"] = a.Eva_ID; tmp["Date"] = (ApSt != null)?ApSt.ApproveDate.ToString().Substring(0, 10) + " " + ((ApSt.ApproveDate.ToString().ElementAt(11) == ':') ? '0' + ApSt.ApproveDate.ToString().Substring(10, 4) : ApSt.ApproveDate.ToString().Substring(10, 5)) : a.Date.ToString().Substring(0, 10) + " " + ((a.Date.ToString().ElementAt(11) == ':') ? '0' + a.Date.ToString().Substring(10, 4) : a.Date.ToString().Substring(10, 5)); a.StartDatePlan = a.StartDatePlan.Replace(" ", "/"); if (a.StartDatePlan.ElementAt(4) == '/') { a.StartDatePlan = a.StartDatePlan.Substring(0, 4) + "0" + a.StartDatePlan.Substring(5); } a.StartDatePlan = a.StartDatePlan.Substring(4, 2) + "/" + a.StartDatePlan.Substring(0, 3) + "/" + a.StartDatePlan.Substring(9, 2); tmp["StartDatePlan"] = a.StartDatePlan; a.FinishDatePlan = a.FinishDatePlan.Replace(" ", "/"); if (a.FinishDatePlan.ElementAt(4) == '/') { a.FinishDatePlan = a.FinishDatePlan.Substring(0, 4) + "0" + a.FinishDatePlan.Substring(5); } a.FinishDatePlan = a.FinishDatePlan.Substring(4, 2) + "/" + a.FinishDatePlan.Substring(0, 3) + "/" + a.FinishDatePlan.Substring(9, 2); tmp["FinishDatePlan"] = a.FinishDatePlan; tmp["FinishEvaDate"] = a.FinishEvaDate; tmp["Function"] = a.Function; tmp["GroupOfStaff"] = a.GroupOfStaff; tmp["PeriodID"] = a.PeriodID; tmp["ProjectCode"] = a.ProjectCode; tmp["ProjectType"] = a.ProjectType; tmp["StartEvaDate"] = a.StartEvaDate; //tmp["employee_language"] = // tblEmployee empTemp = emp.Where(b => b.EmployeeNo.Replace(" ","") == a.em).FirstOrDefault(); tmp["name_language"] = JsonConvert.DeserializeObject <JObject>("{\"EN\":\"" + a.EmployeeFirstName + " " + a.EmployeeLastName + "\",\"TH\":\"" + a.EmployeeFirstNameThai + " " + a.EmployeeLastNameThai + "\"}"); Jeva.Add(tmp); }); return(Jeva); }
public void UpdateHeader([FromBody] List <JObject> Data) { var header = ServiceContainer.GetService <PesWeb.Service.Modules.HeaderManage>(); var header2 = ServiceContainer.GetService <PesWeb.Service.Modules.EvaManage>(); int EvaID = 0; foreach (JObject jo in Data) { if (jo.Count > 3) { header.UpdateScoreData(Convert.ToInt32(jo["EvaId"].ToString()), 0, Convert.ToInt32(jo["Id"].ToString()), jo["Comment"].ToString()); } else { header.UpdateScoreData(Convert.ToInt32(jo["EvaId"].ToString()), Convert.ToInt32(jo["Score"].ToString()), Convert.ToInt32(jo["Id"].ToString()), ""); } EvaID = Convert.ToInt32(jo["EvaId"].ToString()); } int sum = 0, sum2 = 0; List <tblHeaderAdditional> hAd = header.getHeaderAdditional().ToList(); List <tblScore> score = header2.GetAllScore().Where(a => a.Eva_ID == EvaID).OrderBy(a => a.H3_ID).ToList(); List <tblHeader> hd = header.GetAllHeader().ToList(); tblEvaluation eva = header2.GetAllEvaluation().Where(a => a.Eva_ID == EvaID).FirstOrDefault(); List <tblHeaderJob> hj = header.getAllHeaderJob().ToList(); List <tblHeaderJob> hjList = new List <tblHeaderJob>(); hj.ForEach(a => { foreach (JObject jo in Data) { if (Convert.ToInt32(jo["Id"].ToString()) == a.H1_ID) { hjList.Add(a); } } }); foreach (tblHeaderJob th in hjList) { if (hd.Where(a => a.H_ID == th.H1_ID).ToList().Count > 0) { List <tblHeader> H1 = hd.Where(a => a.Parent == th.H1_ID).ToList(); foreach (tblHeader th2 in H1) { List <tblHeader> H2 = hd.Where(a => a.Parent == th2.H_ID).ToList(); foreach (tblHeader th3 in H2) { sum += (int)score.Where(a => a.H3_ID == th3.H_ID).FirstOrDefault().point; } List <tblHeaderAdditional> Hd1 = hAd.Where(a => a.parent == th2.H_ID).ToList(); foreach (tblHeaderAdditional thA in Hd1) { sum += (int)thA.point; } if (H2.Count > 0 || Hd1.Count > 0) { header.UpdateScoreData(EvaID, sum / (H2.Count + Hd1.Count), th2.H_ID, score.Where(a => a.Eva_ID == EvaID && a.H3_ID == th2.H_ID).FirstOrDefault().Comment); sum2 += sum / (H2.Count + Hd1.Count); } sum = 0; } header.UpdateScoreData(EvaID, sum2 / H1.Count, (int)th.H1_ID, score.Where(a => a.Eva_ID == EvaID && a.H3_ID == th.H1_ID).FirstOrDefault().Comment); sum2 = 0; } } sum = 0; sum2 = 0; List <tblHeaderAdditional> hdaList = header.getHeaderAdditional().Where(a => a.Eva_ID == EvaID).ToList(); List <tblHeaderAdditional> hh = hdaList.Where(a => a.parent == 0 && a.Eva_ID == EvaID).ToList(); foreach (tblHeaderAdditional tmp in hh) { List <tblHeaderAdditional> h1 = hdaList.Where(a => a.parent == (-1) * tmp.H_ID).ToList(); foreach (tblHeaderAdditional tmp2 in h1) { List <tblHeaderAdditional> h2 = hdaList.Where(a => a.parent == (-1) * tmp2.H_ID).ToList(); foreach (tblHeaderAdditional tmp3 in h2) { sum += (int)tmp3.point; } sum = sum / (h2.Count); header.UpdateScoreData(EvaID, sum, tmp2.H_ID, tmp2.Comment); sum2 += sum; sum = 0; } sum2 = sum2 / (h1.Count); header.UpdateScoreData(EvaID, sum2, tmp.H_ID, tmp.Comment); } if (EvaID > 0) { header.UpdateEvaluationStatus(EvaID, 1); } tblApprove AllAp = header2.GetAllApprove().Where(a => a.EvaID == EvaID).OrderByDescending(a => a.ID).FirstOrDefault(); tblApproveStatus ApS = header2.GetApproveStatus().Where(a => a.FlowOrder == 1 && a.ApproveID == AllAp.ID).OrderByDescending(a => a.ID).FirstOrDefault(); AllAp.ST = 1; ApS.Status = 1; header2.UpdateApproveData(AllAp); header2.UpdateApproveData(ApS); tblEmployee emp = header2.getEmployees().Where(a => a.EmployeeNo.Replace(" ", "") == eva.EvaluatorNO).FirstOrDefault(); insertLog(emp.EmployeeFirstName + " " + emp.EmployeeLastName, eva.EvaluatorNO, "Update Score of EvaID : " + EvaID); }