mobioffice-cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/.prettierrc +4 -0
  2. package/README.md +1 -0
  3. package/a.js +3 -0
  4. package/lib/index.js +87 -0
  5. package/package.json +50 -0
  6. package/scripts/1.ts +1300 -0
  7. package/scripts/GCloudPubSub/pub-sub-config.json +12 -0
  8. package/scripts/GCloudPubSub/visitorAutoRejection.ts +86 -0
  9. package/scripts/actions/assignUsersFromOneActionToOther.ts +64 -0
  10. package/scripts/actions/assignUsersListToAction.ts +81 -0
  11. package/scripts/actions/getActionsListOfUser.ts +42 -0
  12. package/scripts/actions/getCompanyUserDetails.ts +49 -0
  13. package/scripts/actions/giveActionToUser.ts +41 -0
  14. package/scripts/actions/giveUsersToActivitySelector.ts +56 -0
  15. package/scripts/actions/groupActionsInActivitySelector.ts +101 -0
  16. package/scripts/actions/modifySummaryReportDB.ts +42 -0
  17. package/scripts/actions/setUrlToActionStep.ts +18 -0
  18. package/scripts/actions/syncMySqlAttendanceDBWithFirebase.ts +93 -0
  19. package/scripts/actions/syncMySqlMeetingsDBWithFirebase.ts +103 -0
  20. package/scripts/actions/test.ts +29 -0
  21. package/scripts/actions/transferFeedsOldIdToNew.ts +40 -0
  22. package/scripts/actions/transformUserIntoManager.ts +89 -0
  23. package/scripts/argvConfig.js +9 -0
  24. package/scripts/backUpData/testCode.ts +131 -0
  25. package/scripts/benaraScripts/addWorkAreaMap.ts +46 -0
  26. package/scripts/benaraScripts/add_customers.ts +26 -0
  27. package/scripts/benaraScripts/add_customers_contact.ts +27 -0
  28. package/scripts/benaraScripts/add_empty_work_area.ts +17 -0
  29. package/scripts/benaraScripts/assignManagers.ts +35 -0
  30. package/scripts/benaraScripts/changeCheckInFlag.ts +45 -0
  31. package/scripts/benaraScripts/createCustomerContactsList.ts +170 -0
  32. package/scripts/benaraScripts/createUserByDeletingOldUser.ts +70 -0
  33. package/scripts/benaraScripts/createUsersAreaMapCollection.ts +23 -0
  34. package/scripts/benaraScripts/createWorkAreaMap.ts +24 -0
  35. package/scripts/benaraScripts/mapWorkAreasToUsers.ts +112 -0
  36. package/scripts/companies_data.json +2496 -0
  37. package/scripts/create_or_update_users.ts +31 -0
  38. package/scripts/csvToJson/csvToJson.ts +90 -0
  39. package/scripts/csvToJson/users.json +3896 -0
  40. package/scripts/db.js +27 -0
  41. package/scripts/db.json +13 -0
  42. package/scripts/dbMySql.ts +63 -0
  43. package/scripts/delete_action_steps.ts +11 -0
  44. package/scripts/delete_user.ts +71 -0
  45. package/scripts/dev_companies_data.json +613 -0
  46. package/scripts/enroll.xlsx +0 -0
  47. package/scripts/export_users.ts +72 -0
  48. package/scripts/files/visitorManagementFiles/displayScreen.json +70 -0
  49. package/scripts/files/visitorManagementFiles/init_report_visibility.ts +79 -0
  50. package/scripts/firebaseConfig.js +12 -0
  51. package/scripts/firebaseDocs/deleteIncommingCollection.ts +47 -0
  52. package/scripts/firebaseDocs/updateDoc.ts +43 -0
  53. package/scripts/getActionDataIntoJSON/getActionData.ts +68 -0
  54. package/scripts/get_attendance_by_any_date.ts +14 -0
  55. package/scripts/get_attendance_by_month.ts +12 -0
  56. package/scripts/get_attendance_monthly_by_team.ts +11 -0
  57. package/scripts/get_daily_report.ts +10 -0
  58. package/scripts/get_mangers.ts +13 -0
  59. package/scripts/grant_user_license.ts +18 -0
  60. package/scripts/init_CustomCollection.ts +16 -0
  61. package/scripts/init_action_steps.ts +28 -0
  62. package/scripts/init_actions.ts +31 -0
  63. package/scripts/init_company.ts +18 -0
  64. package/scripts/init_customer_mysql.ts +12 -0
  65. package/scripts/init_feed.ts +4 -0
  66. package/scripts/init_feed_details_screen.ts +14 -0
  67. package/scripts/init_geofence.ts +26 -0
  68. package/scripts/init_print_details_screen.ts +14 -0
  69. package/scripts/init_report_actions.ts +24 -0
  70. package/scripts/init_report_definition_detail.ts +26 -0
  71. package/scripts/init_report_definition_summary.ts +16 -0
  72. package/scripts/init_report_visibility.ts +46 -0
  73. package/scripts/init_user_customcollection.ts +16 -0
  74. package/scripts/json/action.json +21 -0
  75. package/scripts/json/company.json +24 -0
  76. package/scripts/json/report-action.json +13 -0
  77. package/scripts/json/report-def-deet.json +43 -0
  78. package/scripts/json/resp.json +784 -0
  79. package/scripts/json/steps.json +24 -0
  80. package/scripts/json/test.ts +49 -0
  81. package/scripts/mysqlConfig.ts +9 -0
  82. package/scripts/revoke_or_extend_license.ts +14 -0
  83. package/scripts/stream.js +4 -0
  84. package/scripts/testing1.ts +35 -0
  85. package/scripts/update/doc.json +20 -0
  86. package/scripts/update/getDocByPath.ts +34 -0
  87. package/scripts/update/updateDocByPath.ts +47 -0
  88. package/scripts/update/updateUsersOfCompanies.ts +58 -0
  89. package/scripts/update_actions.ts +19 -0
  90. package/scripts/update_actions_steps.ts +19 -0
  91. package/scripts/update_company.ts +19 -0
  92. package/scripts/update_geofence.ts +20 -0
  93. package/scripts/update_managers.ts +16 -0
  94. package/scripts/visitorMgmt/createArea.ts +68 -0
  95. package/scripts/visitorMgmt/createArea.txt +3 -0
  96. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.ts +130 -0
  97. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.txt +18 -0
  98. package/scripts/visitorMgmt/encryptDateString.ts +71 -0
  99. package/scripts/visitorMgmt/makeHostsManagersOfEachOther.ts +117 -0
  100. package/scripts/whatsapp_gupshup/sendMessage.ts +97 -0
  101. package/src/index.ts +87 -0
  102. package/src/models/Feed-Details-Screen.model.ts +29 -0
  103. package/src/models/action.model.ts +355 -0
  104. package/src/models/actions/doffing.ts +71 -0
  105. package/src/models/actions/folding.ts +39 -0
  106. package/src/models/attendance.model.ts +615 -0
  107. package/src/models/cicoPost.model.ts +20 -0
  108. package/src/models/company.model.ts +975 -0
  109. package/src/models/contact-us/resquest.model.ts +87 -0
  110. package/src/models/crud/crud.ts +30 -0
  111. package/src/models/customCollection.model.ts +47 -0
  112. package/src/models/customer/customer.model.ts +85 -0
  113. package/src/models/deviceChangeReq.ts +150 -0
  114. package/src/models/dispatch.model.ts +99 -0
  115. package/src/models/feed.models.ts +104 -0
  116. package/src/models/geofence.model.ts +61 -0
  117. package/src/models/leaveApplicationPost.model.ts +79 -0
  118. package/src/models/license.model.ts +215 -0
  119. package/src/models/log.model.ts +25 -0
  120. package/src/models/meeting.model.ts +80 -0
  121. package/src/models/meter.model.ts +62 -0
  122. package/src/models/missingPunchPost.model.ts +84 -0
  123. package/src/models/offline.model.ts +1133 -0
  124. package/src/models/post.model.ts +105 -0
  125. package/src/models/printDetailsScreen.model.ts +30 -0
  126. package/src/models/pushNotifications/pushNotification.model.ts +17 -0
  127. package/src/models/report-actions.model.ts +57 -0
  128. package/src/models/report-definition-details.model.ts +89 -0
  129. package/src/models/report-definition.model.ts +26 -0
  130. package/src/models/report-definitions-summary.model.ts +59 -0
  131. package/src/models/report-detail-data.model.ts +49 -0
  132. package/src/models/report-visibility.model.ts +44 -0
  133. package/src/models/report.model.ts +179 -0
  134. package/src/models/reportGenerator.model.ts +883 -0
  135. package/src/models/response.model.ts +31 -0
  136. package/src/models/steps.factory.model.ts +195 -0
  137. package/src/models/storeGupShupLog.model.ts +49 -0
  138. package/src/models/summary.model.ts +63 -0
  139. package/src/models/tasks/sub-task-group.model.ts +173 -0
  140. package/src/models/tasks/tags.model.ts +113 -0
  141. package/src/models/tasks/task-group.model.ts +172 -0
  142. package/src/models/tasks/task.model.ts +681 -0
  143. package/src/models/tempCollection.model.ts +398 -0
  144. package/src/models/user.model.ts +319 -0
  145. package/src/models/utility.model.ts +100 -0
  146. package/src/models/visitorManagement/acknowledgement.model.ts +71 -0
  147. package/src/models/visitorManagement/invite.model.ts +406 -0
  148. package/src/models/visitorManagement/newIn.model.ts +82 -0
  149. package/src/models/visitorManagement/selfServe.model.ts +58 -0
  150. package/src/models/worklogPost.model.ts +8 -0
  151. package/src/services/customer.ts +382 -0
  152. package/src/services/meeting.ts +123 -0
  153. package/test/1.ts +13 -0
  154. package/test/db.js +19 -0
  155. package/test/firebaseConfig.js +1 -0
  156. package/tsconfig.json +16 -0
@@ -0,0 +1,615 @@
1
+ import * as admin from "firebase-admin";
2
+ import { Action } from "./action.model";
3
+ import { Company } from "./company.model";
4
+ import { License } from "./license.model";
5
+ import { User } from "./user.model";
6
+ import { Utilities } from "./utility.model";
7
+ import { Pool } from 'mysql2';
8
+ import CurdService from "./crud/crud";
9
+
10
+ class Attendance {
11
+ static async getAttendancebyUser(
12
+ firestore: admin.firestore.Firestore,
13
+ company: string,
14
+ phone: string,
15
+ from_date: string,
16
+ to_date: string,
17
+ isOnlyMonthRequired: boolean
18
+ ) {
19
+ console.log("in getAttendance by user");
20
+ console.log(from_date, to_date);
21
+ let epochFromDate = await Attendance.convertToTimestamp(from_date);
22
+ let epochToDate = await License.convertDatetoTimestamp(to_date);
23
+ let datesInMonthList = await Attendance.getDatesInInterval(
24
+ from_date,
25
+ to_date,
26
+ isOnlyMonthRequired
27
+ );
28
+ let userStartAtDoc: any = Array.apply(
29
+ null,
30
+ Array(datesInMonthList.length)
31
+ ).map(() => {
32
+ return [];
33
+ });
34
+ let userEndAtDoc: any = Array.apply(
35
+ null,
36
+ Array(datesInMonthList.length)
37
+ ).map(() => {
38
+ return [];
39
+ });
40
+ let userId = await User.getUserIdByPhone(firestore, phone);
41
+ let companyId = await Company.getCompanyIdByNickName(firestore, company);
42
+ let actionId = await Action.getActionId(
43
+ firestore,
44
+ companyId,
45
+ "check_in_out"
46
+ );
47
+ if (!actionId) {
48
+ return { data: datesInMonthList, message: "action" };
49
+ }
50
+ let userAttendance_snapshot = await Attendance.getAttendancefromFirestore(
51
+ firestore,
52
+ companyId,
53
+ actionId,
54
+ userId,
55
+ epochFromDate,
56
+ epochToDate
57
+ );
58
+ if (userAttendance_snapshot.empty) {
59
+ return { data: datesInMonthList, message: "data not found" };
60
+ }
61
+ userAttendance_snapshot.forEach((doc) => {
62
+ if (
63
+ epochFromDate <= doc.data().startAt &&
64
+ doc.data().startAt <= epochToDate
65
+ ) {
66
+ let startAt = new Date(doc.data().startAt).toLocaleString("en-GB", {
67
+ year: "numeric",
68
+ month: "numeric",
69
+ day: "numeric",
70
+ hour: "2-digit",
71
+ minute: "2-digit",
72
+ });
73
+ let idx: number = parseInt(startAt.split(",")[0].split("/")[0]) - 1;
74
+ userStartAtDoc[idx].push(startAt.replace(",", ""));
75
+ } else if (
76
+ epochFromDate <= doc.data().endAt &&
77
+ doc.data().endAt <= epochToDate
78
+ ) {
79
+ let endAt = new Date(doc.data().endAt).toLocaleString("en-GB", {
80
+ year: "numeric",
81
+ month: "numeric",
82
+ day: "numeric",
83
+ hour: "2-digit",
84
+ minute: "2-digit",
85
+ });
86
+ let idx: number = parseInt(endAt.split(",")[0].split("/")[0]) - 1;
87
+ userEndAtDoc[idx].push(endAt.replace(",", ""));
88
+ }
89
+ });
90
+ for (let date in datesInMonthList) {
91
+ let startAt = userStartAtDoc[date][userStartAtDoc[date].length - 1]
92
+ ? userStartAtDoc[date][userStartAtDoc[date].length - 1]
93
+ : "";
94
+ let endAt = userEndAtDoc[date][0] ? userEndAtDoc[date][0] : "";
95
+ Object.assign(datesInMonthList[date], { in: startAt }, { status: null });
96
+ Object.assign(datesInMonthList[date], { out: endAt }, { status: null });
97
+ }
98
+ return { data: datesInMonthList, message: "Success" };
99
+ }
100
+
101
+ static async getByDateAttendancebyUser(
102
+ firestore: admin.firestore.Firestore,
103
+ company: string,
104
+ phone: string,
105
+ from_date: string,
106
+ to_date: string
107
+ ) {
108
+ let epochFromDate = await Attendance.convertToTimestamp(from_date);
109
+ let epochToDate = await License.convertDatetoTimestamp(to_date);
110
+ let attendanceObj = {
111
+ "In Time": "",
112
+ "Out Time": "",
113
+ };
114
+ let userStartAt: any = "";
115
+ let userEndAt: any = "";
116
+ let userId = await User.getUserIdByPhone(firestore, phone);
117
+ let companyId = await Company.getCompanyIdByNickName(firestore, company);
118
+ let actionId = await Action.getActionId(
119
+ firestore,
120
+ companyId,
121
+ "check_in_out"
122
+ );
123
+ if (!actionId) {
124
+ return { data: attendanceObj, message: "No action" };
125
+ }
126
+ let userAttendance_snapshot = await Attendance.getAttendancefromFirestore(
127
+ firestore,
128
+ companyId,
129
+ actionId,
130
+ userId,
131
+ epochFromDate,
132
+ epochToDate
133
+ );
134
+ if (userAttendance_snapshot.empty) {
135
+ return { data: attendanceObj, message: "Data not found" };
136
+ }
137
+ userAttendance_snapshot.forEach((doc) => {
138
+ console.log("before if condition", epochFromDate, doc.data().startAt);
139
+ if (
140
+ epochFromDate <= doc.data().startAt &&
141
+ doc.data().startAt <= epochToDate
142
+ ) {
143
+ console.log(epochFromDate, doc.data().startAt);
144
+ let startAt = new Date(doc.data().startAt).toLocaleString("en-GB", {
145
+ year: "numeric",
146
+ month: "numeric",
147
+ day: "numeric",
148
+ hour: "2-digit",
149
+ minute: "2-digit",
150
+ });
151
+ userStartAt = startAt.replace(",", "").split(" ")[1];
152
+ console.log(userStartAt);
153
+ } else if (
154
+ epochFromDate <= doc.data().endAt &&
155
+ doc.data().endAt <= epochToDate
156
+ ) {
157
+ let endAt = new Date(doc.data().endAt).toLocaleString("en-GB", {
158
+ year: "numeric",
159
+ month: "numeric",
160
+ day: "numeric",
161
+ hour: "2-digit",
162
+ minute: "2-digit",
163
+ });
164
+ userEndAt = endAt.replace(",", "").split(" ")[1];
165
+ }
166
+ });
167
+ console.log("startAt", userStartAt);
168
+ console.log("endAt", userEndAt);
169
+ attendanceObj["In Time"] = userStartAt;
170
+ attendanceObj["Out Time"] = userEndAt;
171
+ return { data: attendanceObj, message: "Success" };
172
+ }
173
+
174
+ static async getDatesInMonth(date: string, from_date?: string) {
175
+ console.log("here", date, from_date);
176
+ let startDate;
177
+ const endDate = Number(date.split("-")[0]);
178
+ if (from_date) {
179
+ startDate = Number(from_date.split("-")[0]);
180
+ } else {
181
+ startDate = 1;
182
+ }
183
+ let month = date.split("-")[1];
184
+ let year = date.split("-")[2];
185
+ let getDatesInMonth: object[] = [];
186
+ // let daysinmonth = new Date(parseInt(year), parseInt(month),0).getDate();
187
+ for (startDate; startDate <= endDate; startDate++) {
188
+ getDatesInMonth.push({
189
+ date: `${String(startDate).padStart(2, "0")}/${month}/${year}`,
190
+ in: "",
191
+ out: "",
192
+ status: "",
193
+ });
194
+ }
195
+ console.log(getDatesInMonth);
196
+ return getDatesInMonth;
197
+ }
198
+
199
+ static async getDatesInInterval(
200
+ startDate: string,
201
+ endDate: string,
202
+ isOnlyMonthRequired: boolean
203
+ ) {
204
+ if (isOnlyMonthRequired) {
205
+ return this.getDaysOfMonth(startDate, endDate);
206
+ }
207
+ console.log(startDate, endDate);
208
+ const startYear = Number(startDate.split("-")[2]);
209
+ const startMonth = Number(startDate.split("-")[1]);
210
+ const startDay = Number(startDate.split("-")[0]);
211
+ const endYear = Number(endDate.split("-")[2]);
212
+ const endMonth = Number(endDate.split("-")[1]);
213
+ const endDay = Number(endDate.split("-")[0]);
214
+ let datesInInterval: any[] = [];
215
+ for (let i = startYear; i <= endYear; i++) {
216
+ console.log("year", i);
217
+ const currentYear = i;
218
+ const isStartYear = this.isStartYear(currentYear, startYear);
219
+ const isEndYear = this.isEndYear(currentYear, endYear);
220
+ if (isStartYear && isEndYear) {
221
+ console.log("only year");
222
+ const daysOfYear = this.getDaysOfYear(
223
+ i,
224
+ startMonth,
225
+ endMonth,
226
+ startDay,
227
+ endDay,
228
+ "onlyYear"
229
+ );
230
+ datesInInterval = [...datesInInterval, ...daysOfYear];
231
+ } else if (isStartYear) {
232
+ console.log("start year");
233
+ const daysOfYear = this.getDaysOfYear(
234
+ i,
235
+ startMonth,
236
+ 12,
237
+ startDay,
238
+ endDay,
239
+ "startYear"
240
+ );
241
+ datesInInterval = [...datesInInterval, ...daysOfYear];
242
+ } else if (isEndYear) {
243
+ console.log("end year");
244
+ const daysOfYear = this.getDaysOfYear(
245
+ i,
246
+ 1,
247
+ endMonth,
248
+ startDay,
249
+ endDay,
250
+ "endYear"
251
+ );
252
+ datesInInterval = [...datesInInterval, ...daysOfYear];
253
+ } else {
254
+ console.log("middle year");
255
+ const daysOfYear = this.getDaysOfYear(
256
+ i,
257
+ 1,
258
+ 12,
259
+ startDay,
260
+ endDay,
261
+ "middleYear"
262
+ );
263
+ datesInInterval = [...datesInInterval, ...daysOfYear];
264
+ }
265
+ }
266
+ console.log(datesInInterval);
267
+ return datesInInterval;
268
+ }
269
+
270
+ static isStartMonth(currMonth: number, startMonth: number) {
271
+ return currMonth === startMonth;
272
+ }
273
+
274
+ static isEndMonth(currMonth: number, endMonth: number) {
275
+ return currMonth === endMonth;
276
+ }
277
+
278
+ static isStartYear(currYear: number, startYear: number) {
279
+ return currYear === startYear;
280
+ }
281
+
282
+ static isEndYear(currYear: number, endYear: number) {
283
+ return currYear === endYear;
284
+ }
285
+
286
+ static getDaysOfYear(
287
+ year: number,
288
+ startMonth: number,
289
+ endMonth: number,
290
+ startDay: number,
291
+ endDay: number,
292
+ yearType: string
293
+ ) {
294
+ let datesOfYear: any[] = [];
295
+ console.log(startMonth, endMonth);
296
+ for (let j = startMonth; j < endMonth + 1; j++) {
297
+ console.log("currMonth", j);
298
+ const isStartMonth = this.isStartMonth(j, startMonth);
299
+ const isEndMonth = this.isEndMonth(j, endMonth);
300
+ console.log("isStartMonth", isStartMonth);
301
+ console.log("isEndMonth", isEndMonth);
302
+ if (isStartMonth && isEndMonth && yearType === "onlyYear") {
303
+ console.log("only month");
304
+ const from_date = `${startDay}-${j}-${year}`;
305
+ const to_date = `${endDay}-${j}-${year}`;
306
+ const daysOfMonth = this.getDaysOfMonth(from_date, to_date);
307
+ datesOfYear = [...datesOfYear, ...daysOfMonth];
308
+ } else if (
309
+ isStartMonth &&
310
+ (yearType === "startYear" || yearType === "onlyYear")
311
+ ) {
312
+ console.log("start month");
313
+ const from_date = `${startDay}-${j}-${year}`;
314
+ const lastDateOfMonth = new Date(year, j, 0).getDate();
315
+ const to_date = `${lastDateOfMonth}-${j}-${year}`;
316
+ const daysOfMonth = this.getDaysOfMonth(from_date, to_date);
317
+ datesOfYear = [...datesOfYear, ...daysOfMonth];
318
+ } else if (
319
+ isEndMonth &&
320
+ (yearType === "endYear" || yearType === "onlyYear")
321
+ ) {
322
+ console.log("last month");
323
+ const from_date = `${1}-${j}-${year}`;
324
+ const to_date = `${endDay}-${j}-${year}`;
325
+ const daysOfMonth = this.getDaysOfMonth(from_date, to_date);
326
+ datesOfYear = [...datesOfYear, ...daysOfMonth];
327
+ } else {
328
+ console.log("middle month");
329
+ const from_date = `${1}-${j}-${year}`;
330
+ const lastDateOfMonth = new Date(year, j, 0).getDate();
331
+ const to_date = `${lastDateOfMonth}-${j}-${year}`;
332
+ const daysOfMonth = this.getDaysOfMonth(from_date, to_date);
333
+ datesOfYear = [...datesOfYear, ...daysOfMonth];
334
+ }
335
+ }
336
+ return datesOfYear;
337
+ }
338
+
339
+ static getDaysOfMonth(startDay: string, endDay: string) {
340
+ const datesOfMonth: any = [];
341
+ const start_day = Number(startDay.split("-")[0]);
342
+ const end_day = Number(endDay.split("-")[0]);
343
+ const month = Number(startDay.split("-")[1]);
344
+ const year = Number(startDay.split("-")[2]);
345
+ for (let i = start_day; i <= end_day; i++) {
346
+ const date = `${i.toString().padStart(2, "0")}/${month
347
+ .toString()
348
+ .padStart(2, "0")}/${year}`;
349
+ datesOfMonth.push({
350
+ date: date,
351
+ in: "",
352
+ out: "",
353
+ status: "",
354
+ });
355
+ }
356
+ return datesOfMonth;
357
+ }
358
+
359
+ static async getAttendancefromFirestore(
360
+ firestore: admin.firestore.Firestore,
361
+ companyId: string,
362
+ actionId: string,
363
+ userId: string,
364
+ epochFromDate: number,
365
+ epochToDate: number
366
+ ) {
367
+ let userAttendancebyMonth = await firestore
368
+ .collection("Companies")
369
+ .doc(companyId)
370
+ .collection("Actions")
371
+ .doc(actionId)
372
+ .collection("check_in_out")
373
+ .where("userId", "==", userId)
374
+ .where("createdAt", ">=", epochFromDate)
375
+ .where("createdAt", "<=", epochToDate + 86400000)
376
+ .orderBy("createdAt", "desc")
377
+ .get();
378
+ return userAttendancebyMonth;
379
+ }
380
+
381
+ static async convertToTimestamp(date: any) {
382
+ const [day, month, year] = date.split("-");
383
+ const timestamp = new Date(year, month - 1, day).getTime();
384
+ return timestamp;
385
+ }
386
+
387
+ static async getformateddate(timestamp: number) {
388
+ let temp = new Date(timestamp).toLocaleString("en-GB", {
389
+ year: "numeric",
390
+ month: "numeric",
391
+ day: "numeric",
392
+ hour: "2-digit",
393
+ minute: "2-digit",
394
+ });
395
+ let time = temp.split(",")[1].replace(" ", "");
396
+ let date = temp.split(",")[0].replace(",", "");
397
+ return [date, time];
398
+ }
399
+
400
+ static async getAttendancebyMonth(
401
+ firestore: admin.firestore.Firestore,
402
+ nickName: string,
403
+ phone: string,
404
+ month: string,
405
+ year: string,
406
+ fromDate?: string,
407
+ toDate?: string
408
+ ) {
409
+ let endDate = new Date(parseInt(year), parseInt(month), 0).getDate();
410
+ let from_date;
411
+ let to_date;
412
+ let isOnlyMonthRequired = false;
413
+ if (fromDate && toDate) {
414
+ from_date = fromDate.split("/").join("-");
415
+ to_date = toDate.split("/").join("-");
416
+ } else {
417
+ from_date = `01-${month}-${year}`;
418
+ to_date = `${endDate}-${month}-${year}`;
419
+ isOnlyMonthRequired = true;
420
+ }
421
+ console.log(from_date, to_date);
422
+ return Attendance.getAttendancebyUser(
423
+ firestore,
424
+ nickName,
425
+ phone,
426
+ from_date,
427
+ to_date,
428
+ isOnlyMonthRequired
429
+ );
430
+ }
431
+
432
+ static async getAttendanceMonthlybyTeam(
433
+ firestore: admin.firestore.Firestore,
434
+ nickName: string,
435
+ month: string,
436
+ year: string
437
+ ) {
438
+ let employeeslistbycompany: User[] = await Company.getUsersListbyCompany(
439
+ firestore,
440
+ nickName
441
+ );
442
+ if (employeeslistbycompany.length < 1) {
443
+ return "No employees in present company";
444
+ }
445
+ let employeesAttendance = await Promise.all(
446
+ employeeslistbycompany.map(async (doc) => {
447
+ let userMothlyAttendance = await Attendance.getAttendancebyMonth(
448
+ firestore,
449
+ nickName,
450
+ doc.phone,
451
+ month,
452
+ year
453
+ );
454
+ let employeeName = doc.name;
455
+ if (!employeeName) {
456
+ employeeName = "unknown";
457
+ }
458
+ return { name: employeeName, data: userMothlyAttendance.data };
459
+ })
460
+ );
461
+ return employeesAttendance;
462
+ }
463
+
464
+ static async getDailyReport(
465
+ firestore: admin.firestore.Firestore,
466
+ nickName: string,
467
+ phoneNo: string
468
+ ) {
469
+ let employeeslistbycompany: any[] = await Company.getTeamListOfManager(
470
+ firestore,
471
+ nickName,
472
+ phoneNo
473
+ );
474
+ if (employeeslistbycompany.length < 1) {
475
+ return null;
476
+ }
477
+ let toDate: string = await Attendance.getCurrentdate();
478
+ toDate = toDate.replace(/\//g, "-");
479
+ console.log(toDate);
480
+ let employeesAttendance: object[] = await Promise.all(
481
+ employeeslistbycompany.map(async (doc) => {
482
+ let employeeAttendance: any =
483
+ await Attendance.getByDateAttendancebyUser(
484
+ firestore,
485
+ nickName,
486
+ doc.phone,
487
+ toDate,
488
+ toDate
489
+ );
490
+ let employeeName = doc.name;
491
+ console.log(employeeAttendance);
492
+ if (!employeeName) {
493
+ employeeName = "unknown";
494
+ }
495
+ return { name: employeeName, ...employeeAttendance.data };
496
+ })
497
+ );
498
+ return employeesAttendance;
499
+ }
500
+
501
+ static async getCurrentdate() {
502
+ return new Date().toLocaleDateString("en-GB", { timeZone: "asia/kolkata" });
503
+ }
504
+
505
+ static async getCurrentTime() {
506
+ return new Date().toLocaleTimeString("en-GB", {
507
+ timeZone: "asia/kolkata",
508
+ hour: "2-digit",
509
+ minute: "2-digit",
510
+ hourCycle: "h12",
511
+ });
512
+ }
513
+
514
+ static async uploadEntryToReportDB(attendanceConnection: Pool, info: any) {
515
+ const curdService = new CurdService(attendanceConnection);
516
+ try {
517
+ const time = await Utilities.epochToMySqlDateTime(info.time);
518
+ const qryString = `INSERT INTO attendanceEntries (companyId, employeeName,
519
+ eventType, timeInt, time, actionName, phoneNo, isInactive)
520
+ VALUES ('${info.companyId}',
521
+ '${info.employeeName}',
522
+ '${info.eventType}',
523
+ ${info.time},
524
+ '${time}',
525
+ '${info.actionName}',
526
+ '${info.phoneNo}', false);`;
527
+ const result = await curdService.query(qryString);
528
+ } catch (error: any) {
529
+ console.log(error.message);
530
+ }
531
+ }
532
+
533
+ static async enrollWorkerFaceToDB(connection: Pool, data: any) {
534
+ const curdService = new CurdService(connection)
535
+ try {
536
+ const currentTimestamp = new Date()
537
+ .toISOString()
538
+ .replace(/T/, " ")
539
+ .replace(/\..+/, "");
540
+ const qryString = `INSERT INTO worker_enroll (
541
+ refId, companyId, faceJpg, name, faceTemplates, enrolledBy, dob, proofType, phone, inchargeName, proofImage, createdAt)
542
+ VALUES ('${data.id}', '${data.companyId}', '${data.faceJpg}',
543
+ '${data.name}', '${data.faceTemplates}', '${data.enrolledBy}', '${data.dob}',
544
+ '${data.proofType}','${data.phone}', '${data.inchargeName}', '${data.proofImage}', '${currentTimestamp}');`;
545
+ return await curdService.query(qryString);
546
+ } catch (error: any) {
547
+ console.log(error.message);
548
+ return error;
549
+ }
550
+ }
551
+
552
+ static async checkUserExist(connection: Pool, id: string) {
553
+ const curdService = new CurdService(connection)
554
+ try {
555
+ const qryString = `SELECT * FROM worker_enroll WHERE refId = '${id}'`;
556
+ return await curdService.query(qryString)
557
+ } catch (error: any) {
558
+ console.log(error.message);
559
+ return error;
560
+ }
561
+ }
562
+
563
+ static async updateExistUser(
564
+ connection: Pool,
565
+ data: any,
566
+ id: number
567
+ ) {
568
+ const curdService = new CurdService(connection)
569
+ try {
570
+ const qryString = `UPDATE worker_enroll
571
+ SET companyId = '${data.companyId}', faceJpg = '${data.faceJpg}', faceId = '${data.faceId}', faceName = '${data.faceName}', faceTemplates = '${data.faceTemplates}', Name = '${data.Name}',
572
+ DOB = '${data.DOB}', ProofType = '${data.ProofType}', Phone = '${data.Phone}', InchargeName = '${data.InchargeName}', ProofImage = '${data.ProofImage}', created_at = CURDATE()
573
+ WHERE refId = '${id}';`;
574
+ return await curdService.query(qryString);
575
+ } catch (error: any) {
576
+ console.log(error.message);
577
+ return error;
578
+ }
579
+ }
580
+
581
+ static async workerCheckIn(
582
+ connection: Pool,
583
+ enrollId: number,
584
+ companyId: string,
585
+ actionName: string
586
+ ) {
587
+ const curdService = new CurdService(connection)
588
+ try {
589
+ const qryString = `INSERT INTO worker_attendance (enrollId, companyId, timeStamp, actionType)
590
+ VALUES ('${enrollId}', '${companyId}', NOW(), '${actionName}');`;
591
+ return await curdService.query(qryString);
592
+ } catch (error: any) {
593
+ console.log(error.message);
594
+ return error;
595
+ }
596
+ }
597
+
598
+ static async cicoValidate(
599
+ connection: Pool,
600
+ enrollId: number,
601
+ action: string
602
+ ) {
603
+ const curdService = new CurdService(connection)
604
+ try {
605
+ const currentDate = new Date().toISOString().split("T")[0];
606
+ const qryString = `SELECT * FROM worker_attendance WHERE enrollId = ${enrollId} AND actionType='${action}' AND timeStamp >= '${currentDate} 00:00:00' AND timeStamp <= '${currentDate} 23:59:59';`;
607
+ return await curdService.query(qryString);
608
+ } catch (error: any) {
609
+ console.log(error.message);
610
+ return error;
611
+ }
612
+ }
613
+ }
614
+
615
+ export { Attendance };
@@ -0,0 +1,20 @@
1
+ import { Post } from "./post.model";
2
+ import * as admin from "firebase-admin";
3
+ class CheckInCheckOutPost extends Post {
4
+ actionEvent: string = "";
5
+ actionType: string = "checkInOut";
6
+ actionName: string = "check_in_out";
7
+
8
+ static async sendCICOPost(firestore: admin.firestore.Firestore,
9
+ cicoPost: any) {
10
+ await firestore.collection("Companies")
11
+ .doc(cicoPost.companyId)
12
+ .collection("Actions")
13
+ .doc(cicoPost.actionId)
14
+ .collection(cicoPost.actionName)
15
+ .doc(cicoPost.eventId)
16
+ .set(cicoPost)
17
+ }
18
+ }
19
+
20
+ export { CheckInCheckOutPost };