-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateTimeCardManager.cs
206 lines (165 loc) · 8.37 KB
/
CreateTimeCardManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Geotab;
using Geotab.Checkmate.ObjectModel;
using GeoTab.ELD;
using GTPC.Service.Models;
using GTPC.Service.Entities.Models;
using GTPC.Service.Implementation;
using GTPC.Service.Implementation.Extensions;
using GTPC.Service.Implementation.Models;
using PTC;
using Paycom.Adapters;
namespace Paycom.Managers
{
public class CreateTimeCardManager
{
LogsManager logcycle;
GeotabAPIAdapter geotabCalls;
LastRecordedTime lastRunTime;
PaycomAPIAdapter paycomCalls;
public CreateTimeCardManager()
{
logcycle = new LogsManager();
geotabCalls = new GeotabAPIAdapter();
lastRunTime = new LastRecordedTime();
paycomCalls = new PaycomAPIAdapter();
}
// change to the one method above
public IEnumerable<TimeCardModel> CreatePunches()
{
Log.MethodStart();
Log.Info("Creating log punches....");
List<DutyStatusLogType> bindLogTypes = new List<DutyStatusLogType>();
bindLogTypes.Add(DutyStatusLogType.D);
bindLogTypes.Add(DutyStatusLogType.ON);
bindLogTypes.Add(DutyStatusLogType.YM);
bindLogTypes.Add(DutyStatusLogType.OFF);
bindLogTypes.Add(DutyStatusLogType.SB);
bindLogTypes.Add(DutyStatusLogType.PC);
bindLogTypes.Add(DutyStatusLogType.WT);
DutyStatusLogSearch logSearch = new DutyStatusLogSearch
{
FromDate = lastRunTime.ReadLastRunFile(), // last run datetime, store in a temp file to obtain this, a separate have window service create it. once ask finshes, update file with last run date (dattimenow). Create new class (potentially interface) for it, separate methods that grabs stores and update
ToDate = DateTime.UtcNow,
Statuses = bindLogTypes,
IncludeBoundaryLogs = true
};
Log.Info($"Logsearch for {logSearch.FromDate} to {logSearch.ToDate}...");
List<DutyStatusLog> listOfLogs = geotabCalls.GetLogList(logSearch).OrderBy(y => y.DateTime).OrderBy(x => x.Driver.Id).ToList();
Log.Info($"{listOfLogs.Count()} logs were found...");
List<GeotabInfoModel> listOfGeotabInfo = logcycle.GetGeotabInfo(listOfLogs).ToList();
//TODO: not duplicating the duty status log types
List<TimeCardModel> punches = CreateTimeCard(listOfGeotabInfo);
Log.MethodEnd();
return punches;
}
private List<TimeCardModel> CreateTimeCard(List<GeotabInfoModel> listOfGeotabInfo)
{
Log.MethodStart();
List<TimeCardModel> timeCards = new List<TimeCardModel>();
foreach (GeotabInfoModel record in listOfGeotabInfo)
{
bool previousLogIsOnDuty = false;
bool previousLogIsOffDuty = false;
GeotabInfoModel oldPunch = paycomCalls.IdentifyLastPunch(record);
//var auditLastPunch = paycomCalls.AuditIdentifyLastPunch(record); // testing with punchaudit url
if (oldPunch.PunchType == "ID")
{
previousLogIsOnDuty = true;
previousLogIsOffDuty = false;
}
else if (oldPunch.PunchType == "OD")
{
previousLogIsOnDuty = false;
previousLogIsOffDuty = true;
}
record.Logs = record.Logs.OrderBy(l => l.DateTime).ToList();
List<DutyStatusLog> logs = record.Logs;
for (int i = 0; i < record.Logs.Count; i++)
{
TimeCardModel timeCard = new TimeCardModel();
timeCard.FirstName = record.FirstName;
timeCard.LastName = record.LastName;
timeCard.EmployeeNumber = record.EmployeeNumber;
timeCard.Timezone = record.Timezone;
timeCard.ClockType = "S";
timeCard.EntryType = 1;
switch (logs[i].Status)
{
case DutyStatusLogType.D:
case DutyStatusLogType.ON:
case DutyStatusLogType.YM:
if (previousLogIsOnDuty)
{
continue;
}
else
{
timeCard.PunchType = "ID";
timeCard.PunchTime = logs[i].DateTime.Value.DateTimetoUnixTimeStamp();
timeCards.Add(timeCard);
}
previousLogIsOnDuty = true;
previousLogIsOffDuty = false;
break;
case DutyStatusLogType.OFF:
case DutyStatusLogType.PC:
case DutyStatusLogType.SB:
case DutyStatusLogType.WT:
if (previousLogIsOffDuty)
{
continue;
}
else
{
timeCard.PunchType = "OD";
timeCard.PunchTime = logs[i].DateTime.Value.DateTimetoUnixTimeStamp();
timeCards.Add(timeCard);
}
previousLogIsOffDuty = true;
previousLogIsOnDuty = false;
break;
}
}
};
Log.MethodEnd();
return timeCards;
}
public IEnumerable<PaycomInfoModel> CreatePaycomInfoModel(IEnumerable<GeotabInfoModel> geotabInfo)
{
Log.MethodStart();
List<PaycomInfoModel> finalList = geotabInfo.Select(x => new PaycomInfoModel
{
FirstName = x.FirstName,
LastName = x.LastName,
EmployeeNumber = x.EmployeeNumber,
PunchRecords = paycomCalls.LastRecordedPunches(x)?.ToList() ?? new List<TimeCardModel>()
}).ToList();
Log.Info($"Turning {finalList.Count()} into paycom list to compare...");
return finalList;
}
public IEnumerable<TimeCardModel> CompareGeoToPay(IEnumerable<PaycomInfoModel> paycomInfo, IEnumerable<GeotabInfoModel> geotabInfo)
{
Log.MethodStart();
//List<PaycomInfoModel> finalPaycomPunchList = new List<PaycomInfoModel>();
List<TimeCardModel> paycomInfoMappedToTimeCard = paycomInfo.SelectMany(x => x.PunchRecords).ToList();
List<TimeCardModel> geotabInfoMappedToTimeCard = geotabInfo.MapInfoToPunchType();
//foreach (PaycomInfoModel paycomCard in paycomInfo)
//{
// if (paycomCard.PunchType != null)
// finalPaycomPunchList.Add(paycomCard);
//}
// take the paycom list, converting that list to a new list of timecardmodels, where geotab log datetimes (converted to unix) do not match the paycom punch times in unix
//IEnumerable<TimeCardModel> mismatchList = paycomInfo.SelectMany(x => x.PunchRecords.Where(y => !geotabInfo.SelectMany(a => a.Logs.Select(b => b.DateTime)).Select(b => b.Value.DateTimetoUnixTimeStamp()).Any(c => c.Equals(y.PunchDateTimeInUnix))));
//IEnumerable<TimeCardModel> mismatchList = paycomInfo.SelectMany(x => x.PunchRecords.Where(y => !geotabInfo.SelectMany(a => a.Logs.Select(b => b.DateTime)).Select(b => b.Value.DateTimetoUnixTimeStamp()).Any(c => c.Equals(y.PunchDateTimeInUnix))));
IEnumerable<TimeCardModel> mismatchList = paycomInfoMappedToTimeCard.FindAll(x => !geotabInfoMappedToTimeCard.Any(y => y.Equals(x)));
Log.MethodEnd();
Log.Info($"Number of users that had mismatch: {mismatchList.Count()}");
return mismatchList;
}
}
}