using System; using System.Collections.Generic; using System.Linq; using System.Web; using HRM.BO; using HRM.DA; using HRM.UI.MODELS; using Ease.Core.Model; using System.Data; using Novacode.NETCorePort; using static iTextSharp.text.pdf.AcroFields; namespace HRM.UI.Components { public static class ExtentionMethods { #region Employee Assembler public static UserTModel ConvertToTModel(this Employee oEmp) { UserTModel obj = new UserTModel(); obj = new UserTModel(); obj.PKID = oEmp.ID; obj.Name = oEmp.Name; if (oEmp.Designation != null) { obj.Designation = oEmp.Designation.Name; } return obj; } public static EmployeeTModel ConvertToTModel(this Employee oEmp, List ogrades, List odepartments) { EmployeeTModel obj = new EmployeeTModel(); obj.EmployeeID = oEmp.ID; obj.Name = oEmp.Name; obj.EmployeeNO = oEmp.EmployeeNo; Grade og = ogrades.FirstOrDefault(i => i.ID == oEmp.GradeID); if (og != null) obj.Grade = og.Name; Department od = odepartments.FirstOrDefault(i => i.ID == oEmp.DepartmentID); if (od != null) obj.Grade = od.Name; return obj; } public static List ConvertToTModels(this IEnumerable oEmploye) { List objs = new List(); List ogrades = new GradeService().GetAllPayrollTypes(EnumStatus.Active); List odepartments = new DepartmentService().GetAll(1); // payrolltype foreach (Employee item in oEmploye) { objs.Add(item.ConvertToTModel(ogrades, odepartments)); } return objs; } #endregion #region Leave Assembler public static LeaveTModel ConvertToTModel(this Leave oLeave) { LeaveTModel obj = new LeaveTModel(); obj.PKID = oLeave.ID; obj.Code = oLeave.Code; obj.Description = oLeave.Description; obj.IsHalfDayLeave = oLeave.IsHalfDayLeave; obj.DependsOnHoliday = oLeave.DependsOnHoliday; obj.IsAttachmentNeeded = oLeave.IsAttachmentNeeded; obj.AttachmentMaxDays = oLeave.AttachmentMaxDays; obj.IsLFA = oLeave.IsLFA; return obj; } public static List ConvertToTModels(this IEnumerable oLeaves) { List objs = new List(); foreach (Leave item in oLeaves) { objs.Add(item.ConvertToTModel()); } return objs; } #endregion #region EmpLeaveStatus Assembler public static EmpLeaveStatusTModel ConvertToTModel(this EmpLeaveStatus oEmpLevStatus) { EmpLeaveStatusTModel obj = new EmpLeaveStatusTModel(); obj = new EmpLeaveStatusTModel(); obj.LeaveID = oEmpLevStatus.LeaveId; obj.LeaveName = oEmpLevStatus.Leave != null ? oEmpLevStatus.Leave.Description : new LeaveService().Get(oEmpLevStatus.LeaveId).Description; if (oEmpLevStatus.Leave != null) { obj.LeaveName = oEmpLevStatus.Leave.Description; } obj.Opening = oEmpLevStatus.OpeningBalance; obj.Availed = oEmpLevStatus.LeaveAvailed; obj.LateAttnAdjust = oEmpLevStatus.LateLeaveAdjustmentConsumed; obj.Balance = oEmpLevStatus.ClosingBalance - oEmpLevStatus.LateLeaveAdjustmentConsumed; return obj; } public static List ConvertToTModels(this IEnumerable oLeaves) { List objs = new List(); foreach (EmpLeaveStatus item in oLeaves) { objs.Add(item.ConvertToTModel()); } return objs; } public static GradeTModel ConvertToTModel(this Grade grade) { GradeTModel obj = new GradeTModel(); obj.ID = grade.ID; obj.Name = grade.Name; return obj; } public static List ConvertToTModels(this IEnumerable Grade) { List objs = new List(); foreach (Grade item in Grade) { objs.Add(item.ConvertToTModel()); } return objs; } #endregion #region WF Objects Assemblers //private static PendingJobTModel ConvertIWFTModel(this WFMovementTran oJob, List oWFSetups, List oWFTypes) //{ // PendingJobTModel obj = new PendingJobTModel(); // obj.PKID = oJob.ID; // obj.ObjectID = oJob.ObjectID; // obj.Description = oJob.ObjectDescription; // obj.OperationDate = oJob.Senttime; // var oWFSetup = oWFSetups.FirstOrDefault(x => x.ID == oJob.SetupID); // if (oWFSetup != null) // { // var oWFType = oWFTypes.FirstOrDefault(x => x.ID == oWFSetup.WFTypeId); // if (oWFType != null) // { // obj.Module = oWFType.StatusUpdateTable; // } // } // return obj; //} public static PendingJobTModel ConvertPendingJobWithDetailTModel(this WFMovementTran oJob, int oEmpID, LeaveEntry le) { PendingJobTModel obj = new PendingJobTModel(); WFType oWFType = new WFTypeService().Get(oJob.WFTypeID); obj.PKID = oJob.ID; obj.UserID = oEmpID; obj.ObjectID = oJob.ObjectID; obj.Description = oJob.ObjectDescription.Trim().Trim('.', ','); obj.OperationDate = oJob.Senttime; obj.Remarks = le.Remarks; obj.Module = oWFType.StatusUpdateTable; if (new WFMovementTranService().IsInitiator(oJob.UniqueNumber, oEmpID)) { obj.HasAccept = true; obj.HasReject = obj.HasRevert = obj.HasRedirect = false; obj.AcceptButtonText = "Submit"; } IworkflowInterface initiatingObject = null; switch (obj.Module) { case "LeaveEntry": initiatingObject = new LeaveEntryService().Get(obj.ObjectID); break; //case "HRRequest": // initiatingObject = HRRequest.Get(obj.ObjectID); // break; default: break; } if (initiatingObject != null) { DataTable dt = new LeaveEntryService().GetPendingJobDetail(le.ID); List opJobsDetail = new List(); if (dt.Rows.Count > 0) { opJobsDetail.Add(new PendingJobDetail() { Type = "Applier:", Value = dt.Rows[0]["Applier"].ToString() }); opJobsDetail.Add(new PendingJobDetail() { Type = "Leave Type:", Value = dt.Rows[0]["Leave"].ToString() }); opJobsDetail.Add(new PendingJobDetail() { Type = "From Date:", Value = dt.Rows[0]["FromDate"].ToString() }); opJobsDetail.Add(new PendingJobDetail() { Type = "To Date:", Value = dt.Rows[0]["ToDate"].ToString() }); opJobsDetail.Add(new PendingJobDetail() { Type = "Total Days:", Value = dt.Rows[0]["TotalDays"].ToString() }); opJobsDetail.Add(new PendingJobDetail() { Type = "Remarks:", Value = dt.Rows[0]["Remarks"].ToString() }); } var details = opJobsDetail; obj.Items = details.ConvertPendingJobDetailTModels(); } return obj; } private static PendingJobDetailTModel ConvertPendingJobDetailTModel(this PendingJobDetail oJob) { PendingJobDetailTModel obj = new PendingJobDetailTModel(); obj.Type = oJob.Type; obj.Value = oJob.Value; return obj; } private static List ConvertPendingJobDetailTModels(this IEnumerable oJobs) { List objs = new List(); if (oJobs != null) { foreach (PendingJobDetail item in oJobs) { objs.Add(item.ConvertPendingJobDetailTModel()); } } return objs; } private static PendingJobTModel ConvertPendingJobTModel(this WFMovementTran oJob) { PendingJobTModel obj = new PendingJobTModel(); obj.PKID = oJob.ID; obj.ObjectID = oJob.ObjectID; obj.Description = oJob.ObjectDescription.Trim().Trim('.', ','); obj.OperationDate = oJob.Senttime; obj.Remarks = oJob.Remarks; return obj; } private static List ConvertPendingJobTModel(this DataTable dataTable) { List lsitItems = new List(); if (dataTable.Rows.Count > 0) { foreach (DataRow row in dataTable.Rows) { PendingJobTModel obj = new PendingJobTModel(); obj.PKID = Convert.ToInt32(row["WFMovementTranID"]); obj.ObjectID = Convert.ToInt32(row["ObjectID"]); obj.Description = Convert.ToString(row["ObjectDescription"]).Trim().Trim('.', ','); obj.OperationDate = Convert.ToDateTime(row["Senttime"]); obj.Module = Convert.ToString(row["ModuleName"]); obj.Remarks = Convert.ToString(row["Remarks"]); obj.PendingJobsCount = Convert.ToInt32(row["Jobcount"]); if (obj.PendingJobsCount > 0 && obj.Module.ToLower() == "attendance") { obj.Description = string.Format("{0} pending Attendance Regularization", obj.PendingJobsCount); } lsitItems.Add(obj); } } return lsitItems; } private static NotificationTModel ConvertNotificationTModel(this WFMovementTask oNotifiaction) { NotificationTModel obj = new NotificationTModel(); obj.PKID = oNotifiaction.ID; obj.ObjectID = oNotifiaction.WFMovementTranID; obj.Description = oNotifiaction.Description; obj.OperationDate = oNotifiaction.SentTime; return obj; } public static List ConvertPendingJobTModels(this IEnumerable oJobs) { List objs = new List(); foreach (WFMovementTran item in oJobs) { objs.Add(item.ConvertPendingJobTModel()); } return objs; } public static List ConvertPendingJobTModels(this DataTable oJobs) { List objs = new List(); objs = oJobs.ConvertPendingJobTModel(); return objs; } public static List ConvertToNotificationTModels(this IEnumerable oNotifications) { List objs = new List(); foreach (WFMovementTask item in oNotifications) { objs.Add(item.ConvertNotificationTModel()); } return objs; } #endregion #region DailyAttnProcess Functions private static DailyAttnProcessTModelForLM ConvertToDailyAttnProcessTModelForLM(this DailyAttnProcess oDailyAttnProcess, Shift oShift, Employee oEmp) { DailyAttnProcessTModelForLM obj = new DailyAttnProcessTModelForLM(); obj.PKID = oDailyAttnProcess.ID; obj.EmployeeID = oDailyAttnProcess.EmployeeID; obj.EmployeeNo = oEmp.EmployeeNo; obj.EmployeeName = oEmp.Name; obj.AttnDate = oDailyAttnProcess.AttnDate; obj.InTime = oDailyAttnProcess.InTime; obj.OutTime = oDailyAttnProcess.OutTime; obj.ActualInTime = oDailyAttnProcess.ActualInTime; obj.ActualOutTime = oDailyAttnProcess.ActualOutTime; obj.ActualOT = oDailyAttnProcess.OTHour; obj.AttenType = oDailyAttnProcess.AttenType; obj.WFStatus = oDailyAttnProcess.WFStatus; obj.Comments = oDailyAttnProcess.Comments; obj.Comments = oDailyAttnProcess.EmpRemarks; obj.Name = oShift != null ? oShift.Name : ""; obj.ShiftShortName = oShift != null ? oShift.ShortName : ""; return obj; } private static DailyAttnProcessTModelForLM ConvertToDailyAttnProcessTModelForLM(DataRow orow) { DailyAttnProcessTModelForLM obj = new DailyAttnProcessTModelForLM(); //dap.*, e.EmployeeID, EmployeeNo, e.Name, e.categoryID, e.GradeID, // LocationID, d.name as DesignationName, g.DESCRIPTION GradeName, dept.DESCRIPTION DepartmentName obj.ID = Convert.ToInt32(orow["DailyAttnProcessID"]); obj.PKID = obj.ID; obj.EmployeeID = Convert.ToInt32(orow["EmployeeID"]); obj.EmployeeNo = Convert.ToString(orow["EmployeeNo"]); obj.EmployeeName = Convert.ToString(orow["Name"]); obj.AttnDate = Convert.ToDateTime(orow["AttnDate"]); obj.InTime = (orow["InTime"] != DBNull.Value && orow["InTime"] != null) ? Convert.ToDateTime(orow["InTime"]) : null; obj.OutTime = (orow["OutTime"] != DBNull.Value && orow["OutTime"] != null) ? Convert.ToDateTime(orow["OutTime"]) : null; obj.ActualInTime = (orow["ActualInTime"] != DBNull.Value && orow["ActualInTime"] != null) ? Convert.ToDateTime(orow["ActualInTime"]) : null; obj.ActualOutTime = (orow["ActualOutTime"] != DBNull.Value && orow["ActualOutTime"] != null) ? Convert.ToDateTime(orow["ActualOutTime"]) : null; //var ActualInTimeParam = orow["ActualInTime"]; //if (!(ActualInTimeParam is DBNull)) //{ // obj.ActualInTime = Convert.ToDateTime(orow["ActualInTime"]); //} //var ActualOutTime = orow["ActualInTime"]; //if (!(ActualOutTime is DBNull)) //{ // obj.ActualOutTime = Convert.ToDateTime(orow["ActualOutTime"]); //} // obj.ActualOT = oDailyAttnProcess.OTHour; obj.AttenType = (EnumAttendanceType)Convert.ToInt32(orow["AttenType"]); obj.WFStatus = (EnumWFAttnStatus)Convert.ToInt32(orow["WFStatus"]); obj.EmpRemarks = Convert.ToString(orow["EmpRemarks"]); obj.Comments = Convert.ToString(orow["Comments"]); obj.ShiftShortName = orow["ShortName"] != null ? orow["ShortName"].ToString() : ""; obj.ShiftID = orow["ShiftID"] != DBNull.Value && orow["ShiftID"] != null ? Convert.ToInt32(orow["ShiftID"]) : null; return obj; } public static List ConvertToDailyAttnProcessTModelsForLM(this IEnumerable oDailyAttnProcess) { List objs = new List(); List oShifts = new ShiftService().GetAllShift(); List employees = new EmployeeService().GetAllEmps(); foreach (DailyAttnProcess item in oDailyAttnProcess) { Employee oEmp = employees.Where(x => x.ID == item.EmployeeID).FirstOrDefault(); Shift oShift = new Shift(); if (item.ShiftID != null) oShift = oShifts.FirstOrDefault(x => x.ID == item.ShiftID); else oShift = null; objs.Add(item.ConvertToDailyAttnProcessTModelForLM(oShift, oEmp)); } return objs; } public static List ConvertToDailyAttnProcessTModelsForLM(DataTable lmData) { List objs = new List(); foreach (DataRow item in lmData.Rows) { objs.Add(ExtentionMethods.ConvertToDailyAttnProcessTModelForLM(item)); } return objs; } public static void CheckValidity(DailyAttnProcess oDailyAttnProcess, DailyAttnProcessTModel oDailyAttnProcessTModel) { if (oDailyAttnProcess == null) { throw new CustomException(EnumExceptionType.Error, "Submitted Attendance data not found."); } if (string.IsNullOrWhiteSpace(oDailyAttnProcessTModel.Comments) && oDailyAttnProcessTModel.WFStatus == EnumWFAttnStatus.EmpSubmitted) { throw new CustomException(EnumExceptionType.Validation, "Remarks Cannot Be Empty"); } } public static DailyAttnProcess GetUpdatedNotSubmittedAttnData(this DailyAttnProcessTModel oDailyAttnProcessTModel) { DailyAttnProcess oDailyAttnProcess = new DailyAttnProcessService().Get(oDailyAttnProcessTModel.PKID); CheckValidity(oDailyAttnProcess, oDailyAttnProcessTModel); switch (oDailyAttnProcessTModel.WFStatus) { case EnumWFAttnStatus.None: break; case EnumWFAttnStatus.EmpSubmitted: oDailyAttnProcess.WFStatus = EnumWFAttnStatus.EmpSubmitted; oDailyAttnProcess.AttenType = oDailyAttnProcessTModel.AttenType; if (oDailyAttnProcessTModel.AppliedOT > 0) { oDailyAttnProcess.ApprovedOTHour = oDailyAttnProcessTModel.AppliedOT; oDailyAttnProcess.OtRemarks = oDailyAttnProcessTModel.AppliedOT.ToString(); } oDailyAttnProcess.Comments = oDailyAttnProcessTModel.Comments; oDailyAttnProcess.InTime = oDailyAttnProcessTModel.InTime; oDailyAttnProcess.OutTime = oDailyAttnProcessTModel.OutTime; oDailyAttnProcess.IsManualEntry = true; break; case EnumWFAttnStatus.LMApproved: break; case EnumWFAttnStatus.DHApproved: break; case EnumWFAttnStatus.HRApproved: break; case EnumWFAttnStatus.NotApplicable: oDailyAttnProcess.WFStatus = EnumWFAttnStatus.NotApplicable; break; default: break; } return oDailyAttnProcess; } public static DailyAttnProcessTModel ConvertToDailyAttnProcessTModel(this DailyAttnProcess oDailyAttnProcess, Shift oShift) { DailyAttnProcessTModel obj = new DailyAttnProcessTModel(); obj.ID = oDailyAttnProcess.ID; obj.PKID = oDailyAttnProcess.ID; obj.DailyAttnProcessID = oDailyAttnProcess.ID; obj.EmployeeID = oDailyAttnProcess.EmployeeID; obj.AttnDate = oDailyAttnProcess.AttnDate; obj.InTime = oDailyAttnProcess.InTime; obj.OutTime = oDailyAttnProcess.OutTime; obj.ActualOT = oDailyAttnProcess.OTHour; obj.AttenType = oDailyAttnProcess.AttenType; obj.EmpAttenType = oDailyAttnProcess.AttenType; obj.WFStatus = oDailyAttnProcess.WFStatus; obj.Comments = oDailyAttnProcess.Comments; obj.ShiftShortName = oShift != null ? oShift.ShortName : ""; return obj; } //public static DailyAttnProcessTModel ConvertToDailyAttnProcessTModelRequest(this DailyAttnProcess oDailyAttnProcess, Shift oShift) //{ // DailyAttnProcessTModel obj = new DailyAttnProcessTModel(); // Employee employee = new EmployeeService().Get(oDailyAttnProcess.EmployeeID); // obj.ID = oDailyAttnProcess.ID; // obj.Location = new AttendanceLocationTModel(); // obj.ID = oDailyAttnProcess.ID; // obj.PKID = oDailyAttnProcess.ID; // obj.EmployeeNo = employee.EmployeeNo; // obj.EmployeeName = employee.Name; // obj.ShiftID = oDailyAttnProcess.ShiftID; // obj.DailyAttnProcessID = oDailyAttnProcess.ID; // obj.EmployeeID = oDailyAttnProcess.EmployeeID; // obj.AttnDate = oDailyAttnProcess.AttnDate; // obj.InTime = oDailyAttnProcess.InTime; // obj.OutTime = oDailyAttnProcess.OutTime; // obj.ActualInTime = oDailyAttnProcess.ActualInTime; // obj.ActualOutTime = oDailyAttnProcess.ActualOutTime; // obj.ActualStatus = oDailyAttnProcess.AttenType; // obj.ActualOT = oDailyAttnProcess.OTHour; // obj.AttenType = oDailyAttnProcess.AttenType; // obj.EmpAttenType = oDailyAttnProcess.AttenType; // obj.WFStatus = oDailyAttnProcess.WFStatus; // obj.Comments = oDailyAttnProcess.Comments; // obj.LMComments = oDailyAttnProcess.LMRemarks; // obj.ShiftShortName = oShift != null ? oShift.ShortName : ""; // obj.Location.ZipcodeInTime = oDailyAttnProcess.ZipcodeInTime; // obj.Location.ZipcodeOutTime = oDailyAttnProcess.ZipcodeOutTime; // obj.Location.InTimeLatitude = oDailyAttnProcess.InTimeLatitude; // obj.Location.OutTimeLatitude = oDailyAttnProcess.OutTimeLatitude; // obj.Location.InTimeLongitude = oDailyAttnProcess.InTimeLongitude; // obj.Location.OutTimeLongitude = oDailyAttnProcess.OutTimeLongitude; // obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress; // obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress; // obj.LocationID = oDailyAttnProcess.LocationID; // obj.IsFromMobile = oDailyAttnProcess.IsFromMobile; // obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\n{2} | In: {3} | Out: {4} | {5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); // if (oDailyAttnProcess.InTimeNearestAddress == "" && oDailyAttnProcess.OutTimeNearestAddress != "") // { // //obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || Out: {3} || {4}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); // obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); // } // else if (oDailyAttnProcess.OutTimeNearestAddress == "" && oDailyAttnProcess.InTimeNearestAddress != "") // { // //obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || {4}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.AttenType.ToString()); // obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); // } // else if (oDailyAttnProcess.InTimeNearestAddress != "" && oDailyAttnProcess.OutTimeNearestAddress != "") // { // //obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || Out: {4} || {5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); // obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); // obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); // } // else if (oDailyAttnProcess.InTimeNearestAddress == "" && oDailyAttnProcess.OutTimeNearestAddress == "") // { // //obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || {3}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.AttenType.ToString()); // } // else // { // //obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || Out: {4} || {5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); // obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); // obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); // } // return obj; //} public static DailyAttnProcessTModel ConvertToDailyAttnProcessTModelRequest(this DailyAttnProcess oDailyAttnProcess) { DailyAttnProcessTModel obj = new DailyAttnProcessTModel(); obj.Location = new AttendanceLocationTModel(); obj.ID = oDailyAttnProcess.ID; obj.PKID = oDailyAttnProcess.ID; obj.DailyAttnProcessID = oDailyAttnProcess.ID; obj.EmployeeID = oDailyAttnProcess.EmployeeID; obj.AttnDate = oDailyAttnProcess.AttnDate; obj.ShiftID = oDailyAttnProcess.ShiftID; obj.InTime = oDailyAttnProcess.InTime; obj.OutTime = oDailyAttnProcess.OutTime; obj.ActualInTime = oDailyAttnProcess.ActualInTime; obj.ActualOutTime = oDailyAttnProcess.ActualOutTime; obj.ActualStatus = oDailyAttnProcess.AttenType; obj.ActualOT = oDailyAttnProcess.OTHour; obj.AttenType = oDailyAttnProcess.AttenType; obj.EmpAttenType = oDailyAttnProcess.AttenType; obj.WFStatus = oDailyAttnProcess.WFStatus; obj.Comments = oDailyAttnProcess.Comments; obj.LMComments = oDailyAttnProcess.LMRemarks; obj.Reason = oDailyAttnProcess.Reason; obj.ShiftShortName = string.Empty;// oDailyAttnProcess.ShiftName != null ? oDailyAttnProcess.ShiftName : string.Empty; obj.Location.ZipcodeInTime = oDailyAttnProcess.ZipcodeInTime; obj.Location.ZipcodeOutTime = oDailyAttnProcess.ZipcodeOutTime; obj.Location.InTimeLatitude = oDailyAttnProcess.InTimeLatitude; obj.Location.OutTimeLatitude = oDailyAttnProcess.OutTimeLatitude; obj.Location.InTimeLongitude = oDailyAttnProcess.InTimeLongitude; obj.Location.OutTimeLongitude = oDailyAttnProcess.OutTimeLongitude; obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress; obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress; obj.LocationID = oDailyAttnProcess.LocationID; obj.IsFromMobile = oDailyAttnProcess.IsFromMobile; return obj; } public static DailyAttnProcessTModel ConvertToDailyAttnProcessTModelRequest(this DailyAttnProcess oDailyAttnProcess, Shift oShift, Employee oEmp, bool withString = false) { DailyAttnProcessTModel obj = new DailyAttnProcessTModel(); obj.Location = new AttendanceLocationTModel(); obj.ID = oDailyAttnProcess.ID; obj.PKID = oDailyAttnProcess.ID; obj.DailyAttnProcessID = oDailyAttnProcess.ID; obj.EmployeeID = oDailyAttnProcess.EmployeeID; if (oEmp != null) { obj.EmployeeName = oEmp.Name; obj.EmployeeNo = oEmp.EmployeeNo; } else { obj.EmployeeName = string.Empty; obj.EmployeeNo = string.Empty; } obj.ShiftID = oDailyAttnProcess.ShiftID; obj.EmpAttenType = oDailyAttnProcess.AttenType; obj.AttenType = oDailyAttnProcess.AttenType; obj.AttnDate = oDailyAttnProcess.AttnDate; obj.InTime = oDailyAttnProcess.InTime; obj.OutTime = oDailyAttnProcess.OutTime; obj.ActualInTime = oDailyAttnProcess.ActualInTime; obj.ActualOutTime = oDailyAttnProcess.ActualOutTime; obj.ActualStatus = oDailyAttnProcess.AttenType; obj.ActualOT = oDailyAttnProcess.OTHour; obj.AttenType = oDailyAttnProcess.AttenType; obj.EmpAttenType = oDailyAttnProcess.AttenType; obj.WFStatus = oDailyAttnProcess.WFStatus; obj.Reason = oDailyAttnProcess.Reason; obj.Comments = oDailyAttnProcess.Comments; obj.LMComments = oDailyAttnProcess.LMRemarks; obj.ShiftShortName = oShift != null ? oShift.ShortName : ""; obj.Location.ZipcodeInTime = oDailyAttnProcess.ZipcodeInTime; obj.Location.ZipcodeOutTime = oDailyAttnProcess.ZipcodeOutTime; obj.Location.InTimeLatitude = oDailyAttnProcess.InTimeLatitude; obj.Location.OutTimeLatitude = oDailyAttnProcess.OutTimeLatitude; obj.Location.InTimeLongitude = oDailyAttnProcess.InTimeLongitude; obj.Location.OutTimeLongitude = oDailyAttnProcess.OutTimeLongitude; obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress; obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress; if (withString == true) { if (oDailyAttnProcess.InTimeNearestAddress == "" && oDailyAttnProcess.OutTimeNearestAddress != "") { obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || Out: {3} || {4}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); } else if (oDailyAttnProcess.OutTimeNearestAddress == "" && oDailyAttnProcess.InTimeNearestAddress != "") { obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || {4}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.AttenType.ToString()); obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); } else if (oDailyAttnProcess.InTimeNearestAddress != "" && oDailyAttnProcess.OutTimeNearestAddress != "") { obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || Out: {4} || {5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); } else if (oDailyAttnProcess.InTimeNearestAddress == "" && oDailyAttnProcess.OutTimeNearestAddress == "") { obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || Out: {4} || \n{5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); } else { obj.MobileTeamAttnDescriptionString = string.Format("[{0}] {1}\r\nDate: {2} || In: {3} || Out: {4} || {5}", obj.EmployeeNo, obj.EmployeeName, obj.AttnDate.ToString("dd MMM"), obj.InTime != null ? ((DateTime)obj.InTime).ToString("HH:mm") : "", obj.OutTime != null ? ((DateTime)obj.OutTime).ToString("HH:mm") : " ", obj.AttenType.ToString()); obj.Location.InTimeNearestAddress = oDailyAttnProcess.InTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.InTimeNearestAddress.Length, 42)); obj.Location.OutTimeNearestAddress = oDailyAttnProcess.OutTimeNearestAddress.Substring(0, Math.Min(oDailyAttnProcess.OutTimeNearestAddress.Length, 42)); } } return obj; } //public static List ConvertToDailyAttnProcessTModels(this IEnumerable oDailyAttnProcess) //{ // List objs = new List(); // List oShifts = new ShiftService().GetAllShift(); // foreach (DailyAttnProcess item in oDailyAttnProcess) // { // Shift oShift = oShifts.FirstOrDefault(x => x.ID == item.ShiftID); // objs.Add(item.ConvertToDailyAttnProcessTModelRequest(oShift)); // } // return objs; //} public static List ConvertToDailyAttnProcessTModels(this IEnumerable oDailyAttnProcess, int linemanagerid) { List objs = new List(); //List oShifts = new ShiftService().GetAllShift(); DataTable oShifts = new ShiftService().GetAllShiftWithNoLock(); DataTable empdatatable = new EmployeeService().GetSubordinatesByLineManagerForMobileWithNoLock(linemanagerid); List oEmps = new List(); foreach (DataRow orow in empdatatable.Rows) { Employee emp = new Employee(); emp.ID = Convert.ToInt32(orow["employeeid"]); emp.Name = orow["name"].ToString(); emp.EmployeeNo = orow["employeeno"].ToString(); oEmps.Add(emp); } foreach (DailyAttnProcess item in oDailyAttnProcess) { //Shift oShift = oShifts.FirstOrDefault(x => x.ID == item.ShiftID); DataRow row = (item.ShiftID != null) ? oShifts.Select($"ShiftID = {item.ShiftID}").ToArray().FirstOrDefault() : null; Shift oShift = (row != null) ? new Shift { ID = row.Field("ShiftID"), ShortName = row.Field("ShortName") } : null; Employee oEmp = oEmps.Count > 0 ? oEmps.FirstOrDefault(x => x.ID == item.EmployeeID) : null; objs.Add(item.ConvertToDailyAttnProcessTModelRequest(oShift, oEmp, true)); } return objs; } public static List ConvertToDailyAttnProcessTModels(this IEnumerable oDailyAttnProcess, Employee emp) { List objs = new List(); //List oShifts = new ShiftService().GetAllShift(); DataTable oShifts = new ShiftService().GetAllShiftWithNoLock(); foreach (DailyAttnProcess item in oDailyAttnProcess) { //Shift oShift = oShifts.FirstOrDefault(x => x.ID == item.ShiftID); DataRow row = (item.ShiftID != null) ? oShifts.Select($"ShiftID = {item.ShiftID}").ToArray().FirstOrDefault() : null; Shift oShift = (row != null) ? new Shift { ID = row.Field("ShiftID"), ShortName = row.Field("ShortName") } : null; objs.Add(item.ConvertToDailyAttnProcessTModelRequest(oShift, emp, true)); } return objs; } public static List ConvertToDailyAttnProcessTModels(this IEnumerable oDailyAttnProcess, Employee emp, bool shiftRefresh) { List objs = new List(); foreach (DailyAttnProcess item in oDailyAttnProcess) { objs.Add(item.ConvertToDailyAttnProcessTModelRequest(null, emp, false)); } return objs; } #endregion #region OTPreApproval Assemblers //public static OTPreApprovalTModel ConvertToTModel(this OTPreApproval oModel, Employee oEmp) //{ // return new OTPreApprovalTModel() // { // PKID = oModel.ID, // EmployeeID = oModel.EmployeeID, // EmployeeNo = oEmp.EmployeeNo, // EmployeeName = oEmp.Name, // PreApproveDate = oModel.PreApproveDate, // OTHours = oModel.OTHours, // LMOTHours = oModel.LMOTHour, // WFStatus = oModel.WFStatus, // FromTime = oModel.FromTime, // ToTime = oModel.ToTime, // Reason = oModel.Reason, // LMID = (oModel.LMID != null && !oModel.LMID.IsUnassigned) ? oModel.LMID : 0, // PreApprovalDescription = oModel.PreApprovalDescription // }; //} //public static List ConvertToTModels(this IEnumerable oModels) //{ // List objs = new List(); // if (oModels != null && oModels.Count() > 0) // { // List oEmployees = Employee.GetByEmpIDs(String.Join(",", oModels.Select(x => x.EmployeeID.ToString()).Distinct())); // foreach (OTPreApproval item in oModels) // { // Employee oEmp = oEmployees.FirstOrDefault(x => x.ID == item.EmployeeID); // objs.Add(item.ConvertToTModel(oEmp)); // } // } // return objs; //} #endregion #region OTSubmit Assemblers //public static OTSubmitTModel ConvertToTModel(this OTSubmit oModel, Employee oEmp) //{ // return new OTSubmitTModel() // { // PKID = oModel.ID, // OTSubmitDate = oModel.OTSubmitDate, // FromTime = oModel.FromTime, // ToTime = oModel.ToTime, // SalaryMonth = oModel.SalaryMonth, // EmployeeID = oModel.EmployeeID, // EmployeeNo = oEmp.EmployeeNo, // EmployeeName = oEmp.Name, // OTHours = oModel.OTHours, // Remarks = oModel.Remarks, // OTPreApprovalID = (oModel.OTPreApprovalID != null && !oModel.OTPreApprovalID.IsUnassigned) ? oModel.OTPreApprovalID : 0, // LMID = (oModel.LMID != null && !oModel.LMID.IsUnassigned) ? oModel.LMID : 0, // LMApprovedDate = oModel.LMApprovedDate, // LMOTHour = oModel.LMOTHour, // LMRemarks = oModel.LMRemarks, // DHID = (oModel.DHID != null && !oModel.DHID.IsUnassigned) ? oModel.DHID : 0, // DHApprovedDate = oModel.DHApprovedDate, // DHOTHour = oModel.DHOTHour, // DHRemarks = oModel.DHRemarks, // WFStatus = oModel.WFStatus // }; //} //public static List ConvertToTModels(this IEnumerable oModels) //{ // List objs = new List(); // if (oModels != null && oModels.Count() > 0) // { // List oEmployees = Employee.GetByEmpIDs(String.Join(",", oModels.Select(x => x.EmployeeID.ToString()).Distinct())); // foreach (OTSubmit item in oModels) // { // Employee oEmp = oEmployees.FirstOrDefault(x => x.ID == item.EmployeeID); // objs.Add(item.ConvertToTModel(oEmp)); // } // } // return objs; //} #endregion #region Location Assemblers public static LocationTModel ConvertToTModel(this Location oLocation) { return oLocation == null ? null : new LocationTModel { Id = oLocation.ID, Code = oLocation.Code, Name = oLocation.Name, AttendancePoint = oLocation.AttendancePoint, Latitude = oLocation.Latitude, Longitude = oLocation.Longitude, LatLongSetBy = oLocation.LatLongSetBy, LatLongSetDate = oLocation.LatLongSetDate, LatLongApproveStatus = oLocation.LatLongApproveStatus }; } public static List ConvertToTModels(this IEnumerable oLocations) { List objs = new List(); foreach (Location item in oLocations) { objs.Add(item.ConvertToTModel()); } return objs; } #endregion #region Location Assemblers public static EmpFieldTrack ConvertToTModel(this EmpFieldTrackTModel empFieldTrackModel) { return empFieldTrackModel == null ? null : new EmpFieldTrack { EmployeeID = empFieldTrackModel.EmployeeID, LocationID = empFieldTrackModel.LocationID ?? 0, Latitude = empFieldTrackModel.Latitude, Longitude = empFieldTrackModel.Longitude, Client = empFieldTrackModel.Client, NearestAddress = empFieldTrackModel.NearestAddress, Remarks = empFieldTrackModel.Remarks, TrackType = empFieldTrackModel.TrackType, TranDateTime = DateTime.Now, ZipCode = empFieldTrackModel.ZipCode }; } //public static List ConvertToTModels(this IEnumerable oLocations) //{ // List objs = new List(); // foreach (Location item in oLocations) // { // objs.Add(item.ConvertToTModel()); // } // return objs; //} #endregion } }