public static ReturnObject CheckPOOOHours(string current) { outofoffice_apply page_object = new outofoffice_apply(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); JObject current_data = new JObject(); string EmailMessage = string.Empty, retrun_message = string.Empty; int ooo_type = 0, ooo_hours = 0, ooo_hours_current = 0; string employee_code = string.Empty, employee_name = string.Empty, from_date = string.Empty, from_time = string.Empty, to_date = string.Empty, to_time = string.Empty, from_date_time = string.Empty, to_date_time = string.Empty, display_message = string.Empty, username = string.Empty, query = string.Empty; try { current_data = JObject.Parse(current); employee_code = current_data["employee_id"].ToString(); employee_name = current_data["employee_name"].ToString(); from_date_time = current_data["in_date"].ToString(); to_date_time = current_data["out_date"].ToString(); ooo_hours_current = Convert.ToInt32(current_data["total_hour"].ToString()); DateTime date = Convert.ToDateTime(from_date_time).Date; from_date_time = new DateTime(date.Year, date.Month, 1).ToString("dd-MMM-yyyy"); to_date_time = Convert.ToDateTime(from_date_time).AddMonths(1).AddDays(-1).ToString("dd-MMM-yyyy"); from_date_time = from_date_time + " 00:00"; to_date_time = to_date_time + " 23:59"; ooo_type = Convert.ToInt32(current_data["outofoffice"].ToString()); if (ooo_type == 1) { query = "select sum(DATEdiff(MINUTE,fromdatetime,todatetime)) from outoffoffice where Emp_ID='" + employee_code + "' and FromDateTime >='" + from_date_time + "' and ToDateTime<='" + to_date_time + "' and OOO_type=1"; ooo_hours = db_connection.ExecuteQuery_WithReturnValueInteger(query); ooo_hours_current = ooo_hours_current + ooo_hours; if (ooo_hours_current > 180) { display_message = "Used hours of personal out of office time off is " + ooo_hours + " Minutes, you have left only " + (180 - ooo_hours) + " Minutes."; return_object.status = "confirm-personal-ooo_hours"; return_object.return_data = display_message; } else { return_object = SaveOutOfOffice(current); } } else { return_object = SaveOutOfOffice(current); } } catch (Exception ex) { Logger.LogException(ex, page, "CHECHK_FOR_PERSONAL_TYPE"); return_object.status = "error"; return_object.return_data = "An error occurred while checking personal ooo hours. Please try again. If the error persists, please contact Support."; } return(return_object); }
public static ReturnObject SaveOutOfOffice(string current) { outofoffice_apply page_object = new outofoffice_apply(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); JObject current_data = new JObject(); string EmailMessage = string.Empty, retrun_message = string.Empty; int ooo_id = 0, access_level = 0, record_count = 0, ooo_type = 0, ooo_hours = 0; string employee_code = string.Empty, employee_name = string.Empty, from_date = string.Empty, from_time = string.Empty, to_date = string.Empty, to_time = string.Empty, from_date_time = string.Empty, to_date_time = string.Empty, reason = string.Empty, action_employee_code = string.Empty, username = string.Empty, query = string.Empty; try { access_level = Convert.ToInt32(HttpContext.Current.Session["access_level"].ToString()); username = HttpContext.Current.Session["employee_id"].ToString(); action_employee_code = HttpContext.Current.Session["employee_name"].ToString(); current_data = JObject.Parse(current); employee_code = current_data["employee_id"].ToString(); employee_name = current_data["employee_name"].ToString(); from_date = current_data["in_date"].ToString(); from_time = current_data["in_time"].ToString(); from_date_time = from_date + " " + from_time; to_date = current_data["out_date"].ToString(); to_time = current_data["out_time"].ToString(); to_date_time = to_date + " " + to_time; ooo_hours = Convert.ToInt32(current_data["total_hour"].ToString()); ooo_type = Convert.ToInt32(current_data["outofoffice"].ToString()); reason = current_data["reason"].ToString(); query = "select count(*) from outoffoffice where Emp_ID='" + employee_code + "' and (('" + from_date_time + "' between FromDateTime and ToDateTime) or ('" + to_date_time + "' between FromDateTime and ToDateTime)) "; record_count = db_connection.GetRecordCount(query); if (record_count == 0) { query = "select count(*) from outoffoffice where Emp_ID='" + employee_code + "' and ( FromDateTime >='" + from_date_time + "' and ToDateTime<='" + to_date_time + "') "; record_count = db_connection.GetRecordCount(query); } if (record_count == 0) { query = "insert into outoffoffice (Emp_ID,Emp_Name,OOO_type,FromDateTime,ToDateTime,Status,OOO_Minutes,Reason,Manager_Status,HR_Status,Manager_Name,Manager_Remark)values ("; query += "'" + employee_code + "','" + employee_name + "'," + ooo_type + ",'" + from_date_time + "','" + to_date_time + "',1," + ooo_hours + ","; if (access_level == 1 && employee_code != HttpContext.Current.Session["employee_id"].ToString())//Manager and other employee { query += "'" + reason + "',2,1,'" + action_employee_code + "','' )"; } else if (access_level == 1 && employee_code == HttpContext.Current.Session["employee_id"].ToString())//Manager and himself { query += "'" + reason + "',1,0,'','' )"; } else if (access_level == 2)//employee { query += "'" + reason + "',1,0,'','' )"; } else if (access_level == 3)//HR { query += "'" + reason + "',2,2,'','' )"; } db_connection.ExecuteQuery_WithOutReturnValue(query); return_object.status = "success"; retrun_message = "Out off Office Punch submitted successfully"; } else { return_object.status = "error"; retrun_message = "Out off Office Punch Already been submitted for the selected dates. Please try with different dates."; } //Auto Approval when HR submits ooo punch for employee if ((access_level == 0 || access_level == 3) && employee_code != HttpContext.Current.Session["employee_id"].ToString()) { query = "select OOO_ID from outoffoffice where Emp_ID='" + employee_code + "' and FromDateTime='" + from_date_time + "' and ToDateTime='" + to_date_time + "' "; ooo_id = db_connection.ExecuteQuery_WithReturnValueInteger(query); query = "update outoffoffice set Status=2 where OOO_ID=" + ooo_id; db_connection.ExecuteQuery_WithOutReturnValue(query); return_object.status = "success"; retrun_message += " and approved by HR"; } /*Add previous ooo hours to applying hours*/ int Total_OOO_Minutes = 0; string fromdatetime = from_date_time, todatetime = string.Empty; DateTime date = Convert.ToDateTime(fromdatetime).Date; fromdatetime = new DateTime(date.Year, date.Month, 1).ToString("dd-MMM-yyyy"); todatetime = Convert.ToDateTime(fromdatetime).AddMonths(1).AddDays(-1).ToString("dd-MMM-yyyy"); fromdatetime = fromdatetime + " 00:00"; todatetime = todatetime + " 23:59"; query = "select OOO_ID from outoffoffice where OOO_type=" + ooo_type + " and Emp_ID='" + employee_code + "' and FromDateTime='" + from_date_time + "' and ToDateTime='" + to_date_time + "' "; ooo_id = db_connection.ExecuteQuery_WithReturnValueInteger(query); query = "Select top 1 Total_OOO_Minutes from outoffoffice where OOO_type=" + ooo_type + " and OOO_ID!= " + ooo_id + "and Emp_ID='" + employee_code + "' and FromDateTime>='" + fromdatetime + "' and ToDateTime<='" + todatetime + "' order by OOO_ID desc"; Total_OOO_Minutes = db_connection.ExecuteQuery_WithReturnValueInteger(query); Total_OOO_Minutes = Total_OOO_Minutes + ooo_hours; query = "update outoffoffice set Total_OOO_Minutes=" + Total_OOO_Minutes + " where OOO_ID=" + ooo_id; db_connection.ExecuteQuery_WithOutReturnValue(query); SendMail(employee_code, employee_name, from_date_time, to_date_time, reason, 0); return_object.return_data = retrun_message; } catch (Exception ex) { Logger.LogException(ex, page, "SAVE_OUTOFFOFFICE_PUNCH"); return_object.status = "error"; return_object.return_data = "An error occurred while saving Out Off Office Punch. Please try again. If the error persists, please contact Support."; } return(return_object); }
public static ReturnObject ValidateEmployeeId(string employee_id) { outofoffice_apply page_object = new outofoffice_apply(); ReturnObject return_object = new ReturnObject(); DBConnection db_connection = new DBConnection(); DataTable Branchlisttable = new DataTable(); DataTable CoManagerID_data = new DataTable(); DataTable innermanagertable = new DataTable(); string employee_name = string.Empty, BranchList = string.Empty, ismanager = string.Empty, ishr = string.Empty, query = string.Empty, deligationmanager = string.Empty, CoManagerID = string.Empty, InnerManagers = string.Empty; int IsDelegationMngr = 0; try { query = "Select Emp_Name from EmployeeMaster where Emp_Code='" + employee_id + "'"; employee_name = db_connection.ExecuteQuery_WithReturnValueString(query); IsDelegationMngr = db_connection.ExecuteQuery_WithReturnValueInteger("Select COUNT(DelidationManagerID) from TbAsignDelegation Where DelidationManagerID='" + HttpContext.Current.Session["employee_id"].ToString() + "' And DeliationStatus=1 and Convert(date,Getdate())>=Convert(date,Fromdate) And Convert(date,Getdate())<=Convert(date,Todate)"); if (IsDelegationMngr > 0) { query = "Select ManagerId from TbAsignDelegation Where DelidationManagerID='" + HttpContext.Current.Session["employee_id"].ToString() + "' And DeliationStatus=1 and Convert(date,Getdate())>=Convert(date,Fromdate) And Convert(date,Getdate())<=Convert(date,Todate)"; CoManagerID_data = db_connection.ReturnDataTable(query); if (CoManagerID_data.Rows.Count > 0) { foreach (DataRow dr in CoManagerID_data.Rows) { CoManagerID += "'" + dr["ManagerId"] + "',"; } CoManagerID = CoManagerID.TrimEnd(','); } } if (string.IsNullOrEmpty(CoManagerID)) { CoManagerID = "'Empty'"; } query = "Select BranchCode From TbManagerHrBranchMapping Where ManagerID='" + HttpContext.Current.Session["employee_id"].ToString() + "'"; Branchlisttable = db_connection.ReturnDataTable(query); if (Branchlisttable.Rows.Count > 0) { foreach (DataRow dr in Branchlisttable.Rows) { BranchList += "'" + dr["BranchCode"] + "',"; } } BranchList = BranchList.TrimEnd(','); if (string.IsNullOrEmpty(BranchList)) { BranchList = "'Empty'"; } if (!string.IsNullOrEmpty(employee_id)) { if (!db_connection.RecordExist("select count(*) from employeeMaster where emp_Code='" + employee_id + "' and emp_status=1")) { return_object.status = "error"; return_object.return_data = "Employee doesn't Exist."; return(return_object); } if (employee_id.Trim() != HttpContext.Current.Session["employee_id"].ToString()) { if (Convert.ToInt32(HttpContext.Current.Session["access_level"].ToString()) == 1 || Convert.ToInt32(HttpContext.Current.Session["access_level"].ToString()) == 3) { if (!db_connection.RecordExist("select count(*) from employeeMaster where emp_Code='" + employee_id.Trim() + "' and emp_status=1 and (managerid In('" + HttpContext.Current.Session["employee_id"].ToString() + "'," + CoManagerID + ") Or Emp_Branch In (" + BranchList + "))")) { return_object.status = "error"; return_object.return_data = "Entered Employee id does not belongs to this manager."; return(return_object); } } } if (string.IsNullOrEmpty(employee_name)) { employee_name = ""; } return_object.status = "success"; return_object.return_data = employee_id.ToString() + "," + employee_name.ToString(); } } catch (Exception ex) { Logger.LogException(ex, page, "VALIDATE_EMPLOYEE_ID"); return_object.status = "error"; return_object.return_data = "An error occurred while loading EmployeeId. Please try again. If the error persists, please contact Support."; } return(return_object); }