1
|
using MinovaIS.MinovaES.Business.AuthorizationObject;
|
2
|
using MinovaIS.MinovaES.Core.Application.Message;
|
3
|
using MinovaIS.MinovaES.Core.Util;
|
4
|
using MinovaIS.MinovaES.Data.Access;
|
5
|
using MinovaIS.MinovaES.Data.Core;
|
6
|
using System;
|
7
|
using System.Collections.Generic;
|
8
|
using System.Configuration;
|
9
|
using System.Linq;
|
10
|
using System.Text;
|
11
|
using System.Threading.Tasks;
|
12
|
|
13
|
namespace MinovaIS.MinovaES.Business.TM
|
14
|
{
|
15
|
public class TimeManagement : ITimeManagament
|
16
|
{
|
17
|
public void GenerateWSCalender(IDatabase db, string WorkscheduleType, string IDType, string Year, string Begda, string Endda,
|
18
|
string Country, bool forceAction, bool simulate, string Token, ref MinovaMessage errorMessage)
|
19
|
{
|
20
|
(db as DatabaseBase).EnableTransaction = true;
|
21
|
try
|
22
|
{
|
23
|
(db as DatabaseBase).Database.BeginTransaction();
|
24
|
UserData user = UserData.GetByToken(Token);
|
25
|
Dictionary<string, object> data = new Dictionary<string, object>();
|
26
|
string startdate = "";
|
27
|
string lastdate = "";
|
28
|
string last = "";
|
29
|
string now8 = DateConverter.Instance.DatetimeToDateStrDB8(DateTime.Now);
|
30
|
|
31
|
if (IDType == "0")
|
32
|
{
|
33
|
startdate = Year + "0101";
|
34
|
lastdate = Year + "1231";
|
35
|
List<WhereClause> onWhere = new List<WhereClause>();
|
36
|
onWhere.Add(new WhereClause { FieldName = "Country", Operator = WhereClauseOperator.Equal, TargetValue = Country.ToString() });
|
37
|
onWhere.Add(new WhereClause { FieldName = "WorkScheduleType", Operator = WhereClauseOperator.Equal, TargetValue = WorkscheduleType.ToString() });
|
38
|
onWhere.Add(new WhereClause { FieldName = "Year", Operator = WhereClauseOperator.Equal, TargetValue = Year.ToString() });
|
39
|
var existData = db.GetData("PHRTMWSCAL", onWhere);
|
40
|
if (existData.Count() > 0)
|
41
|
{
|
42
|
MinovaDataTable ent = new MinovaDataTable(db, "PHRTMWSCAL");
|
43
|
ent.FieldStructure = db.GetTableStructure("PHRTMWSCAL").ToList();
|
44
|
ent.DeleteDataRows = existData.ToList();
|
45
|
ent.SaveNonCommit();
|
46
|
}
|
47
|
}
|
48
|
else if (IDType == "1")
|
49
|
{
|
50
|
startdate = Begda;
|
51
|
lastdate = Endda;
|
52
|
Year = DateConverter.Instance.DateStrDB8ToDatetime(startdate).Year.ToString();
|
53
|
List<WhereClause> onWhere = new List<WhereClause>();
|
54
|
onWhere.Add(new WhereClause { FieldName = "Country", Operator = WhereClauseOperator.Equal, TargetValue = Country.ToString() });
|
55
|
onWhere.Add(new WhereClause { FieldName = "WorkScheduleType", Operator = WhereClauseOperator.Equal, TargetValue = WorkscheduleType.ToString() });
|
56
|
var existData = db.GetData("PHRTMWSCAL", onWhere).Where(x => x["DateSpecified"].ToString().CompareTo(Begda) >= 0
|
57
|
&& x["DateSpecified"].ToString().CompareTo(Endda) <= 0);
|
58
|
if (existData.Count() > 0)
|
59
|
{
|
60
|
MinovaDataTable ent = new MinovaDataTable(db, "PHRTMWSCAL");
|
61
|
ent.FieldStructure = db.GetTableStructure("PHRTMWSCAL").ToList();
|
62
|
ent.DeleteDataRows = existData.ToList();
|
63
|
ent.SaveNonCommit();
|
64
|
}
|
65
|
}
|
66
|
|
67
|
last = DateConverter.Instance.DatetimeToDateStrDB8(DateConverter.Instance.DateStrDB8ToDatetime(lastdate).AddDays(1));
|
68
|
|
69
|
string date = startdate;
|
70
|
var day = DateConverter.Instance.DateStrDB8ToDatetime(startdate).DayOfWeek.ToString();
|
71
|
int startdaynum = 0;
|
72
|
if (day.ToLower() == "monday") startdaynum = 1;
|
73
|
else if (day.ToLower() == "tuesday") startdaynum = 2;
|
74
|
else if (day.ToLower() == "wednesday") startdaynum = 3;
|
75
|
else if (day.ToLower() == "thursday") startdaynum = 4;
|
76
|
else if (day.ToLower() == "friday") startdaynum = 5;
|
77
|
else if (day.ToLower() == "saturday") startdaynum = 6;
|
78
|
else startdaynum = 7;
|
79
|
|
80
|
int daynum = startdaynum;
|
81
|
List<WhereClause> _onWhere = new List<WhereClause>();
|
82
|
_onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.LessThanEqual, TargetValue = now8.ToString() });
|
83
|
_onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.GreaterThanEqual, TargetValue = now8.ToString() });
|
84
|
_onWhere.Add(new WhereClause { FieldName = "WorkScheduleType", Operator = WhereClauseOperator.Equal, TargetValue = WorkscheduleType.ToString() });
|
85
|
var wsGen = db.GetData("PHRTMWSGEN", _onWhere);
|
86
|
|
87
|
int wsgennum = wsGen.Count();
|
88
|
while(date != last)
|
89
|
{
|
90
|
data.Clear();
|
91
|
List<Dictionary<string, object>> dataInput = new List<Dictionary<string, object>>();
|
92
|
if (daynum > wsgennum)
|
93
|
{
|
94
|
daynum = 1;
|
95
|
}
|
96
|
_onWhere.Clear();
|
97
|
_onWhere.Add(new WhereClause { FieldName = "Date", Operator = WhereClauseOperator.Equal, TargetValue = date.ToString() });
|
98
|
_onWhere.Add(new WhereClause { FieldName = "Country", Operator = WhereClauseOperator.Equal, TargetValue = Country.ToString() });
|
99
|
var holiday_calendar = db.GetData("PHRTMHOLCAL", _onWhere).FirstOrDefault();
|
100
|
|
101
|
_onWhere.Clear();
|
102
|
var hr_tm_public_holiday = db.GetData("PHRTMPUBHOL", _onWhere);
|
103
|
var hr_tm_holiday_calendar = db.GetData("PHRTMHOLCAL", _onWhere);
|
104
|
|
105
|
var fix_public_holiday = (from y in hr_tm_public_holiday
|
106
|
from z in hr_tm_holiday_calendar
|
107
|
where date == string.Concat(Year, y["Date"].ToString()) &&
|
108
|
y["Fixed"].ToString() == "Yes" &&
|
109
|
z["Country"].ToString() == Country &&
|
110
|
y["PublicHoliday"].ToString() == z["PublicHoliday"].ToString()
|
111
|
select new {
|
112
|
DayType = z["DayType"].ToString(),
|
113
|
PhID = z["PublicHoliday"].ToString()
|
114
|
}).FirstOrDefault();
|
115
|
if (holiday_calendar != null)
|
116
|
{
|
117
|
data.Add("DayType", holiday_calendar["DayType"].ToString());
|
118
|
data.Add("PublicHoliday", holiday_calendar["PublicHoliday"].ToString());
|
119
|
}
|
120
|
else if (fix_public_holiday != null)
|
121
|
{
|
122
|
data.Add("DayType", fix_public_holiday.DayType);
|
123
|
data.Add("PublicHoliday", fix_public_holiday.PhID);
|
124
|
}
|
125
|
else
|
126
|
{
|
127
|
string seq = "";
|
128
|
if(daynum < 10)
|
129
|
{
|
130
|
seq = (0 + daynum).ToString();
|
131
|
}
|
132
|
else
|
133
|
{
|
134
|
seq = daynum.ToString();
|
135
|
}
|
136
|
_onWhere.Clear();
|
137
|
_onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.LessThanEqual, TargetValue = now8.ToString() });
|
138
|
_onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.GreaterThanEqual, TargetValue = now8.ToString() });
|
139
|
_onWhere.Add(new WhereClause { FieldName = "WorkScheduleType", Operator = WhereClauseOperator.Equal, TargetValue = WorkscheduleType.ToString() });
|
140
|
_onWhere.Add(new WhereClause { FieldName = "SequenceDay", Operator = WhereClauseOperator.Equal, TargetValue = seq.ToString() });
|
141
|
var wsgen = db.GetData("PHRTMWSGEN", _onWhere).Select( a => a["DayType"].ToString()).FirstOrDefault();
|
142
|
if(wsgen != null)
|
143
|
{
|
144
|
var dty = wsgen;
|
145
|
data.Add("DayType", dty.ToString());
|
146
|
}
|
147
|
}
|
148
|
data.Add("Country", Country);
|
149
|
data.Add("WorkScheduleType", WorkscheduleType);
|
150
|
data.Add("Year", Year);
|
151
|
data.Add("DateSpecified", date);
|
152
|
data.Add("CreateBy", user.UserName);
|
153
|
data.Add("CreateDate", DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now));
|
154
|
data.Add("ChangeBy", user.UserName);
|
155
|
data.Add("ChangeDate", DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now));
|
156
|
dataInput.Add(data);
|
157
|
MinovaDataTable ent = new MinovaDataTable(db, "PHRTMWSCAL");
|
158
|
ent.FieldStructure = db.GetTableStructure("PHRTMWSCAL").ToList();
|
159
|
if (ent.DeleteDataRows != null)
|
160
|
{
|
161
|
ent.DeleteDataRows.Clear();
|
162
|
}
|
163
|
if (ent.UpdateDataRows != null)
|
164
|
{
|
165
|
ent.UpdateDataRows.Clear();
|
166
|
}
|
167
|
if (ent.NewDataRows != null)
|
168
|
{
|
169
|
ent.NewDataRows.Clear();
|
170
|
}
|
171
|
ent.NewDataRows = dataInput.ToList();
|
172
|
ent.SaveNonCommit();
|
173
|
|
174
|
daynum++;
|
175
|
date = DateConverter.Instance.DatetimeToDateStrDB8(DateConverter.Instance.DateStrDB8ToDatetime(date).AddDays(1));
|
176
|
|
177
|
}
|
178
|
if (simulate)
|
179
|
{
|
180
|
(db as DatabaseBase).Database.RollBackTransaction();
|
181
|
}
|
182
|
else
|
183
|
{
|
184
|
(db as DatabaseBase).Database.CommitTransaction();
|
185
|
}
|
186
|
}
|
187
|
catch (Exception exc)
|
188
|
{
|
189
|
errorMessage.type = MessageType.Error;
|
190
|
errorMessage.text = exc.Message;
|
191
|
(db as DatabaseBase).Database.RollBackTransaction();
|
192
|
}
|
193
|
finally
|
194
|
{
|
195
|
(db as DatabaseBase).Database.CloseTransaction();
|
196
|
}
|
197
|
}
|
198
|
|
199
|
public IEnumerable<Dictionary<string, object>> LoadWSCalender(IDatabase db, string WorkscheduleType, string Country, ref MinovaMessage errorMessage)
|
200
|
{
|
201
|
IEnumerable<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
|
202
|
try
|
203
|
{
|
204
|
List<WhereClause> onWhere = new List<WhereClause>();
|
205
|
onWhere.Add(new WhereClause { FieldName = "Country", Operator = WhereClauseOperator.Equal, TargetValue = Country.ToString() });
|
206
|
onWhere.Add(new WhereClause { FieldName = "WorkScheduleType", Operator = WhereClauseOperator.Equal, TargetValue = WorkscheduleType.ToString() });
|
207
|
result = db.GetData("PHRTMWSCAL", onWhere);
|
208
|
}
|
209
|
catch(Exception exc)
|
210
|
{
|
211
|
errorMessage.type = MessageType.Error;
|
212
|
errorMessage.text = exc.Message;
|
213
|
}
|
214
|
return result;
|
215
|
}
|
216
|
|
217
|
public IEnumerable<Dictionary<string, object>> GenerateAbsenceQuota(IDatabase db, string MenuID, string GenerateType, string StartDate, string EndDate, string PeriodFrom, string PeriodTo, string YosMin, string YosMax,
|
218
|
string StartDeduction, string EndDeduction, string QuotaType, string Quota, string EmpType, string EmpSubType,
|
219
|
string GradeStart, string GradeEnd, string EmpStart, string EmpEnd, string Token, ref MinovaMessage errorMessage)
|
220
|
{
|
221
|
IEnumerable<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
|
222
|
try
|
223
|
{
|
224
|
UserData user = UserData.GetByToken(Token);
|
225
|
AuthObject auth = new AuthObject();
|
226
|
var listemp = auth.ListEmpIDAuth(MenuID, Token);
|
227
|
string _listemp = listemp.FirstOrDefault()["EmployeeID"].ToString().Replace(" ", "");
|
228
|
result = ProcessGenerate(db, user, GenerateType, StartDate, EndDate, PeriodFrom, PeriodTo,
|
229
|
YosMin, YosMax, StartDeduction, EndDeduction, QuotaType, Quota,
|
230
|
EmpType, EmpSubType, GradeStart, GradeEnd, EmpStart, EmpEnd, _listemp);
|
231
|
}
|
232
|
catch (Exception exc)
|
233
|
{
|
234
|
errorMessage.type = MessageType.Error;
|
235
|
errorMessage.text = exc.Message;
|
236
|
}
|
237
|
return result;
|
238
|
}
|
239
|
|
240
|
public IEnumerable<Dictionary<string, object>> ProcessGenerate(IDatabase db, UserData user, string GenerateType, string StartDate, string EndDate, string PeriodFrom, string PeriodTo, string YosMin, string YosMax,
|
241
|
string StartDeduction, string EndDeduction, string QuotaType, string Quota, string EmpType, string EmpSubType,
|
242
|
string GradeStart, string GradeEnd, string EmpStart, string EmpEnd, string ListEmp)
|
243
|
{
|
244
|
IEnumerable<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
|
245
|
try
|
246
|
{
|
247
|
//string[] ListEmployee_ = ListEmp.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
248
|
//string ListEmployee = "";
|
249
|
//if (ListEmp.Length > 0)
|
250
|
//{
|
251
|
// ListEmployee = ListEmp.Substring(0, ListEmp.Length - 1);
|
252
|
//}
|
253
|
//else { ListEmployee = "0"; }
|
254
|
string message = string.Empty;
|
255
|
string codeHiring = string.Empty;
|
256
|
string now8 = DateConverter.Instance.DatetimeToDateStrDB8(DateTime.Now);
|
257
|
string now14 = DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now);
|
258
|
int StDed = Convert.ToInt32(StartDeduction);
|
259
|
int EtDed = Convert.ToInt32(EndDeduction);
|
260
|
DataConfigSection config = ConfigurationManager.GetSection("MinovaDataAccess") as DataConfigSection;
|
261
|
string dbType = config.DatabaseType.ToString();
|
262
|
string noLock = string.Empty;
|
263
|
if (dbType == "SQLServer")
|
264
|
{
|
265
|
noLock = " WITH (NOLOCK) ";
|
266
|
}
|
267
|
StringBuilder strBuild = new StringBuilder();
|
268
|
string Query = string.Empty;
|
269
|
StringBuilder strQuery = new StringBuilder();
|
270
|
List<WhereClause> onWhere = new List<WhereClause>();
|
271
|
onWhere.Add(new WhereClause { FieldName = "Parameter", Operator = WhereClauseOperator.Equal, TargetValue = "DATE_SPESIFICATION_HIRING_DATE_CODE" });
|
272
|
var genParam = db.GetData("PCMEPGENPARAM", onWhere).FirstOrDefault();
|
273
|
if (genParam != null) { codeHiring = genParam["Value1"].ToString(); }
|
274
|
if(GenerateType == "0")//General
|
275
|
{
|
276
|
string _date = StartDate.Substring((StartDate.Length - 2), 2);
|
277
|
string _month = StartDate.Substring(4, 2);
|
278
|
DateTime startDeduc = DateConverter.Instance.DateStrDB8ToDatetime(StartDate).AddMonths(StDed);
|
279
|
DateTime endDeduc = DateConverter.Instance.DateStrDB8ToDatetime(EndDate).AddMonths(EtDed);
|
280
|
string stdeduc = DateConverter.Instance.DatetimeToDateStrDB8(startDeduc);
|
281
|
string etdeduc = DateConverter.Instance.DatetimeToDateStrDB8(endDeduc);
|
282
|
strQuery.AppendFormat(" SELECT DISTINCT * FROM ( SELECT DISTINCT '{1}' AS StartDate, " +
|
283
|
" '{2}' AS EndDate, " +
|
284
|
" md1.EmployeeID , " +
|
285
|
" CASE WHEN ( md39.Date IS NULL ) THEN md15.HiringDate " +
|
286
|
" ELSE md39.Date " +
|
287
|
" END AS HiringDate , " +
|
288
|
" DATEDIFF(month,( CASE WHEN ( md39.Date IS NULL ) " +
|
289
|
" THEN md15.HiringDate " +
|
290
|
" ELSE md39.Date " +
|
291
|
" END ), '{1}') / 12 AS YearOfService , " +
|
292
|
" '{3}' AS AbsenceQuotaType, " +
|
293
|
" '1' AS Sequence, " +
|
294
|
" '{4}' AS StartDeduction, " +
|
295
|
" '{5}' AS EndDeduction, " +
|
296
|
" '{6}' AS OriginalQuota, " +
|
297
|
" '{7}' AS RemainQuota, " +
|
298
|
" md1.FullName , " +
|
299
|
" md2.EmployeeOffice , " +
|
300
|
" md2.EmployeeArea , " +
|
301
|
" md2.EmployeeType , " +
|
302
|
" md2.EmployeeSubType , " +
|
303
|
" md3.PayrollGrade, " +
|
304
|
" '{8}' AS CreateBy, " +
|
305
|
" '{12}' AS CreateDate, " +
|
306
|
" '{8}' AS ChangeBy, " +
|
307
|
" '{12}' AS ChangeDate " +
|
308
|
" FROM PHRPA0015 md15 " + noLock +
|
309
|
" LEFT JOIN PHRPA0039 md39 " + noLock + "ON md15.EmployeeID = md39.EmployeeID " +
|
310
|
" AND md39.DateType = '{9}' " +
|
311
|
" INNER JOIN PHRPA0001 md1 " + noLock + " ON md15.EmployeeID = md1.EmployeeID " +
|
312
|
" AND md1.StartDate <= '{0}' " +
|
313
|
" AND md1.EndDate >= '{0}' " +
|
314
|
" INNER JOIN PHRPA0002 md2 " + noLock + " ON md1.EmployeeID = md2.EmployeeID " +
|
315
|
" AND md2.StartDate <= '{0}' " +
|
316
|
" AND md2.EndDate >= '{0}' " +
|
317
|
" LEFT JOIN PHRPA0003 md3 " + noLock + " ON md1.EmployeeID = md3.EmployeeID " +
|
318
|
" AND md3.StartDate <= '{0}' " +
|
319
|
" AND md3.EndDate >= '{0}' " +
|
320
|
" WHERE md2.EmployeeID IN ( {13} ) " +
|
321
|
" ) AS tb " +
|
322
|
" WHERE 1 = 1 AND YearOfService BETWEEN {10} AND {11} ", now8, StartDate, EndDate, QuotaType, stdeduc,
|
323
|
etdeduc, Quota, Quota, user.UserName, codeHiring, YosMin, YosMax, now14, ListEmp);
|
324
|
if(!string.IsNullOrWhiteSpace(EmpType))
|
325
|
{
|
326
|
strQuery.AppendFormat(" AND EmployeeType = '{0}' ", EmpType);
|
327
|
}
|
328
|
if(!string.IsNullOrWhiteSpace(EmpSubType))
|
329
|
{
|
330
|
strQuery.AppendFormat(" AND EmployeeSubType = '{0}' ", EmpSubType);
|
331
|
}
|
332
|
if (!string.IsNullOrWhiteSpace(GradeStart))
|
333
|
{
|
334
|
strQuery.AppendFormat(" AND ( PayrollGrade >= '{0}' AND PayrollGrade <= '{1}' ) ", GradeStart, GradeEnd);
|
335
|
}
|
336
|
if (!string.IsNullOrWhiteSpace(EmpStart))
|
337
|
{
|
338
|
strQuery.AppendFormat(" AND ( EmployeeID >= '{0}' AND EmployeeID <= '{1}' ) ", EmpStart, EmpEnd);
|
339
|
}
|
340
|
|
341
|
onWhere.Clear();
|
342
|
onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.Equal, TargetValue = StartDate });
|
343
|
onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.Equal, TargetValue = EndDate });
|
344
|
onWhere.Add(new WhereClause { FieldName = "AbsenceQuotaType", Operator = WhereClauseOperator.Equal, TargetValue = QuotaType });
|
345
|
var exist = db.GetData("PHRPA0017", onWhere);
|
346
|
|
347
|
var r = db.GetDataDictionaryByQuery(strQuery.ToString(), ref message);
|
348
|
|
349
|
var res = r.Where(x => !exist.Select(b => b["EmployeeID"].ToString()).Contains(x["EmployeeID"].ToString()));
|
350
|
//res = res.Where(x => ListEmp.Select(b => b["EmployeeID"].ToString()).Contains(x["EmployeeID"].ToString()));
|
351
|
|
352
|
result = res.ToList();
|
353
|
|
354
|
if(!string.IsNullOrWhiteSpace(message))
|
355
|
{
|
356
|
throw new Exception(message);
|
357
|
}
|
358
|
}
|
359
|
else if(GenerateType == "1")// hiring date
|
360
|
{
|
361
|
string _sdate = "";
|
362
|
string _edate = "";
|
363
|
string StartDeduc = "";
|
364
|
string EndDeduc = "";
|
365
|
string startdate = PeriodFrom + "01";
|
366
|
string Year = PeriodFrom.Substring(0, 4);
|
367
|
string NextYear = (Convert.ToInt32(Year) + 1).ToString();
|
368
|
string MonthSt = PeriodFrom.Substring(4, 2);
|
369
|
string MonthEt = PeriodTo.Substring(4, 2);
|
370
|
strQuery.AppendFormat(" SELECT DISTINCT * FROM ( SELECT DISTINCT '' AS StartDate, " +
|
371
|
" '' AS EndDate, " +
|
372
|
" CASE WHEN ( md39.Date IS NULL ) THEN md15.HiringDate " +
|
373
|
" ELSE md39.Date " +
|
374
|
" END AS HiringDate , " +
|
375
|
" CASE WHEN ( md39.Date IS NULL ) " +
|
376
|
" THEN SUBSTRING(md15.HiringDate, 5, 2) " +
|
377
|
" ELSE SUBSTRING(md39.Date, 5, 2) " +
|
378
|
" END AS HiringMonth , " +
|
379
|
" DATEDIFF(year, ( CASE WHEN ( md39.Date IS NULL ) " +
|
380
|
" THEN md15.HiringDate " +
|
381
|
" ELSE md39.Date " +
|
382
|
" END ), '{1}') AS YearOfService , " +
|
383
|
" md1.EmployeeID , " +
|
384
|
" '{2}' AS AbsenceQuotaType, " +
|
385
|
" '1' AS Sequence, " +
|
386
|
" '' AS StartDeduction, " +
|
387
|
" '' AS EndDeduction, " +
|
388
|
" '{3}' AS OriginalQuota, " +
|
389
|
" '{3}' AS RemainQuota, " +
|
390
|
" md1.FullName , " +
|
391
|
" md2.EmployeeOffice , " +
|
392
|
" md2.EmployeeArea , " +
|
393
|
" md2.EmployeeType , " +
|
394
|
" md2.EmployeeSubType , " +
|
395
|
" md3.PayrollGrade, " +
|
396
|
" '{4}' AS CreateBy, " +
|
397
|
" '{10}' AS CreateDate, " +
|
398
|
" '{4}' AS ChangeBy, " +
|
399
|
" '{10}' AS ChangeDate " +
|
400
|
" FROM PHRPA0015 md15 " + noLock +
|
401
|
" LEFT JOIN PHRPA0039 md39 " + noLock + " ON md15.EmployeeID = md39.EmployeeID " +
|
402
|
" AND md39.DateType = '{9}' " +
|
403
|
" INNER JOIN PHRPA0001 md1 " + noLock + " ON md15.EmployeeID = md1.EmployeeID " +
|
404
|
" AND md1.StartDate <= '{0}' " +
|
405
|
" AND md1.EndDate >= '{0}' " +
|
406
|
" INNER JOIN PHRPA0002 md2 " + noLock + " ON md1.EmployeeID = md2.EmployeeID " +
|
407
|
" AND md2.StartDate <= '{0}' " +
|
408
|
" AND md2.EndDate >= '{0}' " +
|
409
|
" INNER JOIN PHRPA0003 md3 " + noLock + " ON md1.EmployeeID = md3.EmployeeID " +
|
410
|
" AND md3.StartDate <= '{0}' " +
|
411
|
" AND md3.EndDate >= '{0}' " +
|
412
|
" WHERE md2.EmployeeID IN ( {11} ) " +
|
413
|
" ) AS tbl " +
|
414
|
" WHERE 1 = 1 " +
|
415
|
" AND HiringMonth BETWEEN '{5}' AND '{6}' " +
|
416
|
" AND YearOfService BETWEEN {7} AND {8} ", now8, startdate, QuotaType, Quota,
|
417
|
user.UserName, MonthSt, MonthEt, YosMin, YosMax, codeHiring, now14, ListEmp);
|
418
|
if (!string.IsNullOrWhiteSpace(EmpType))
|
419
|
{
|
420
|
strQuery.AppendFormat(" AND EmployeeType = '{0}' ", EmpType);
|
421
|
}
|
422
|
if (!string.IsNullOrWhiteSpace(EmpSubType))
|
423
|
{
|
424
|
strQuery.AppendFormat(" AND EmployeeSubType = '{0}' ", EmpSubType);
|
425
|
}
|
426
|
if (!string.IsNullOrWhiteSpace(GradeStart))
|
427
|
{
|
428
|
strQuery.AppendFormat(" AND ( PayrollGrade >= '{0}' AND PayrollGrade <= '{1}' ) ", GradeStart, GradeEnd);
|
429
|
}
|
430
|
if (!string.IsNullOrWhiteSpace(EmpStart))
|
431
|
{
|
432
|
strQuery.AppendFormat(" AND ( EmployeeID >= '{0}' AND EmployeeID <= '{1}' ) ", EmpStart, EmpEnd);
|
433
|
}
|
434
|
|
435
|
var __result = db.GetDataDictionaryByQuery(strQuery.ToString(), ref message);
|
436
|
|
437
|
if (!string.IsNullOrWhiteSpace(message))
|
438
|
{
|
439
|
throw new Exception(message);
|
440
|
}
|
441
|
else
|
442
|
{
|
443
|
if(__result.Count() > 0)
|
444
|
{
|
445
|
foreach(var res in __result)
|
446
|
{
|
447
|
_sdate = Year + res["HiringMonth"].ToString() + "01";
|
448
|
DateTime beforeDate = DateConverter.Instance.DateStrDB8ToDatetime(_sdate).AddMonths(-1);
|
449
|
var stdate = DateConverter.Instance.DatetimeToDateStrDB8(beforeDate);
|
450
|
var month = beforeDate.Month;
|
451
|
var monthbefore = stdate.Substring(4, 2);
|
452
|
var day = DateTime.DaysInMonth(Convert.ToInt32(NextYear), month);
|
453
|
_edate = NextYear + monthbefore + day.ToString();
|
454
|
|
455
|
DateTime SDED = DateConverter.Instance.DateStrDB8ToDatetime(_sdate).AddMonths(StDed);
|
456
|
DateTime EDED = DateConverter.Instance.DateStrDB8ToDatetime(_edate).AddMonths(EtDed);
|
457
|
StartDeduc = DateConverter.Instance.DatetimeToDateStrDB8(SDED);
|
458
|
EndDeduc = DateConverter.Instance.DatetimeToDateStrDB8(EDED);
|
459
|
if(res.ContainsKey("StartDate"))
|
460
|
{
|
461
|
res["StartDate"] = _sdate;
|
462
|
}
|
463
|
if (res.ContainsKey("EndDate"))
|
464
|
{
|
465
|
res["EndDate"] = _edate;
|
466
|
}
|
467
|
if(res.ContainsKey("StartDeduction"))
|
468
|
{
|
469
|
res["StartDeduction"] = StartDeduc;
|
470
|
}
|
471
|
if (res.ContainsKey("EndDeduction"))
|
472
|
{
|
473
|
res["EndDeduction"] = EndDeduc;
|
474
|
}
|
475
|
}
|
476
|
}
|
477
|
|
478
|
onWhere.Clear();
|
479
|
//onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.Equal, TargetValue = StartDate });
|
480
|
//onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.Equal, TargetValue = EndDate });
|
481
|
onWhere.Add(new WhereClause { FieldName = "AbsenceQuotaType", Operator = WhereClauseOperator.Equal, TargetValue = QuotaType });
|
482
|
var PHRPA0017 = db.GetData("PHRPA0017", onWhere);
|
483
|
var exist = PHRPA0017.Where(x => __result.Select(b => b["EmployeeID"].ToString()).Contains(x["EmployeeID"].ToString()) &&
|
484
|
__result.Select(b => b["StartDate"].ToString()).Contains(x["StartDate"].ToString()) &&
|
485
|
__result.Select(b => b["EndDate"].ToString()).Contains(x["EndDate"].ToString())).ToList();
|
486
|
|
487
|
__result = __result.Where(x => !exist.Select(b => b["EmployeeID"].ToString()).Contains(x["EmployeeID"].ToString())).ToList();
|
488
|
|
489
|
//__result = __result.Where(x => ListEmp.Select(b => b["EmployeeID"].ToString()).Contains(x["EmployeeID"].ToString())).ToList();
|
490
|
}
|
491
|
|
492
|
result = __result;
|
493
|
}
|
494
|
}
|
495
|
catch(Exception exc)
|
496
|
{
|
497
|
throw new Exception((exc.InnerException == null) ? exc.Message
|
498
|
: (exc.InnerException.InnerException == null) ? exc.InnerException.Message
|
499
|
: exc.InnerException.InnerException.Message);
|
500
|
}
|
501
|
|
502
|
return result;
|
503
|
}
|
504
|
|
505
|
public int GetDateWorkDays
|
506
|
(string emp_id, string keyDateStart, string keyDateEnd)
|
507
|
{
|
508
|
#region Set Parameter Awal
|
509
|
|
510
|
IDatabase db = DatabaseFactory.Create();
|
511
|
int _result = 0;
|
512
|
Dictionary<string, object> _SqlWhere = new Dictionary<string, object>();
|
513
|
List<WhereClause> onWhere = new List<WhereClause>();
|
514
|
onWhere.Clear();
|
515
|
var PHRTMDAYTYP = db.GetData("PHRTMDAYTYP", onWhere);
|
516
|
|
517
|
#endregion
|
518
|
|
519
|
#region Get Tipe Workschedule
|
520
|
onWhere.Clear();
|
521
|
onWhere.Add(new WhereClause
|
522
|
{
|
523
|
FieldName = "EmployeeID",
|
524
|
Operator = WhereClauseOperator.Equal,
|
525
|
TargetValue = emp_id
|
526
|
});
|
527
|
onWhere.Add(new WhereClause
|
528
|
{
|
529
|
FieldName = "StartDate",
|
530
|
Operator = WhereClauseOperator.LessThanEqual,
|
531
|
TargetValue = keyDateStart
|
532
|
});
|
533
|
onWhere.Add(new WhereClause
|
534
|
{
|
535
|
FieldName = "EndDate",
|
536
|
Operator = WhereClauseOperator.GreaterThanEqual,
|
537
|
TargetValue = keyDateStart
|
538
|
});
|
539
|
var PHRPA0025 = db.GetData("PHRPA0025", onWhere);
|
540
|
|
541
|
if (PHRPA0025.Count() == 0)
|
542
|
{
|
543
|
return _result;
|
544
|
}
|
545
|
|
546
|
var _WSType = PHRPA0025.FirstOrDefault()["WorkScheduleType"].ToString();
|
547
|
#endregion
|
548
|
|
549
|
#region Cek MD Personal Data
|
550
|
onWhere.Clear();
|
551
|
onWhere.Add(new WhereClause
|
552
|
{
|
553
|
FieldName = "EmployeeID",
|
554
|
Operator = WhereClauseOperator.Equal,
|
555
|
TargetValue = emp_id
|
556
|
});
|
557
|
onWhere.Add(new WhereClause
|
558
|
{
|
559
|
FieldName = "StartDate",
|
560
|
Operator = WhereClauseOperator.GreaterThanEqual,
|
561
|
TargetValue = keyDateStart
|
562
|
});
|
563
|
onWhere.Add(new WhereClause
|
564
|
{
|
565
|
FieldName = "EndDate",
|
566
|
Operator = WhereClauseOperator.LessThanEqual,
|
567
|
TargetValue = keyDateEnd
|
568
|
});
|
569
|
var PHRPA0125 = db.GetData("PHRPA0125", onWhere);
|
570
|
#endregion
|
571
|
|
572
|
#region Kalkulasi Durasi cuti Memakai MD Personal WS
|
573
|
if (PHRPA0125.Count() > 0)
|
574
|
{
|
575
|
foreach (var _Items in PHRPA0125)
|
576
|
{
|
577
|
var _Flag = PHRTMDAYTYP.Where(a => a["DayType"].ToString() == _Items["DayType"].ToString())
|
578
|
.Select(a => a["Flag"].ToString()).FirstOrDefault();
|
579
|
|
580
|
if (_Flag == "WORK")
|
581
|
_result++;
|
582
|
}
|
583
|
|
584
|
return _result;
|
585
|
}
|
586
|
#endregion
|
587
|
|
588
|
#region Cek WS kalender
|
589
|
|
590
|
_SqlWhere.Add("0WorkScheduleType", _WSType);
|
591
|
_SqlWhere.Add("5DateSpecified", keyDateStart);
|
592
|
_SqlWhere.Add("3DateSpecified", keyDateEnd);
|
593
|
|
594
|
var PHRTMWSCAL = getData_SQL("PHRTMWSCAL", _SqlWhere);
|
595
|
|
596
|
if (PHRTMWSCAL.Count() == 0)
|
597
|
{ return _result; }
|
598
|
|
599
|
#endregion
|
600
|
|
601
|
#region Kalkulasi durasi cuti dari kalender WS
|
602
|
|
603
|
foreach (var _Items in PHRTMWSCAL)
|
604
|
{
|
605
|
var _Flag = PHRTMDAYTYP.Where(a => a["DayType"].ToString() == _Items["DayType"].ToString())
|
606
|
.Select(a => a["Flag"].ToString()).FirstOrDefault();
|
607
|
|
608
|
if (_Flag == "WORK")
|
609
|
_result++;
|
610
|
}
|
611
|
|
612
|
return _result;
|
613
|
|
614
|
#endregion
|
615
|
}
|
616
|
|
617
|
public IEnumerable<Dictionary<string, object>> getData_SQL
|
618
|
(string _tablename, Dictionary<string, object> _param)
|
619
|
{
|
620
|
#region system param
|
621
|
IEnumerable<Dictionary<string, object>> _result = new List<Dictionary<string, object>>();
|
622
|
List<WhereClause> onWhere = new List<WhereClause>();
|
623
|
DbParameter[] paramIn = new DbParameter[] { };
|
624
|
DbParameter[] paramOut = new DbParameter[] { };
|
625
|
string errorMessage = string.Empty;
|
626
|
StringBuilder strBuild = new StringBuilder();
|
627
|
DataConfigSection config = ConfigurationManager.GetSection("MinovaDataAccess") as DataConfigSection;
|
628
|
DbAccess dbAccess = new DbAccess(config.DatabaseType, config.Server, config.Database, config.User, config.Password);
|
629
|
string dbType = config.DatabaseType.ToString();
|
630
|
decimal __i = 0;
|
631
|
string noLock = " WITH (nolock)";
|
632
|
if (dbType != "SQLServer")
|
633
|
{
|
634
|
noLock = "";
|
635
|
}
|
636
|
#endregion
|
637
|
|
638
|
try
|
639
|
{
|
640
|
#region Create SQL string
|
641
|
string _sql_str = "SELECT * FROM " + _tablename + " ";
|
642
|
strBuild.Append(_sql_str);
|
643
|
|
644
|
if (_param != null && _param.Count() > 0)
|
645
|
{
|
646
|
foreach (var _item in _param)
|
647
|
{
|
648
|
if (__i == 0)
|
649
|
{
|
650
|
_sql_str += "WHERE ";
|
651
|
}
|
652
|
else
|
653
|
{
|
654
|
_sql_str += " AND ";
|
655
|
}
|
656
|
|
657
|
__i++;
|
658
|
|
659
|
var _key_name = _item.Key.ToString();
|
660
|
var _value_name = _item.Value.ToString();
|
661
|
var _type = _key_name.Substring(0, 1);
|
662
|
|
663
|
_sql_str += _key_name.Substring(1, _key_name.Length - 1) + " ";
|
664
|
|
665
|
switch (_type)
|
666
|
{
|
667
|
case "0":
|
668
|
_sql_str += " = " + "'" + _value_name + "'";
|
669
|
break;
|
670
|
case "1":
|
671
|
_sql_str += " <> " + "'" + _value_name + "'";
|
672
|
break;
|
673
|
case "2":
|
674
|
_sql_str += " < " + "'" + _value_name + "'";
|
675
|
break;
|
676
|
case "3":
|
677
|
_sql_str += " <= " + "'" + _value_name + "'";
|
678
|
break;
|
679
|
case "4":
|
680
|
_sql_str += " > " + "'" + _value_name + "'";
|
681
|
break;
|
682
|
case "5":
|
683
|
_sql_str += " >= " + "'" + _value_name + "'";
|
684
|
break;
|
685
|
case "6":
|
686
|
_sql_str += " LIKE " + "'%" + _value_name + "%'";
|
687
|
break;
|
688
|
default:
|
689
|
break;
|
690
|
}
|
691
|
}
|
692
|
}
|
693
|
#endregion
|
694
|
|
695
|
#region Execute get Data
|
696
|
_result = dbAccess.ExecuteToDictionary(paramIn, ref paramOut, _sql_str, ref errorMessage);
|
697
|
#endregion
|
698
|
}
|
699
|
catch (Exception _exc)
|
700
|
{ }
|
701
|
|
702
|
return _result;
|
703
|
}
|
704
|
|
705
|
private object obj = new object();
|
706
|
public void ClockInAttendance(string Token, ref MinovaMessage msg)
|
707
|
{
|
708
|
UserData user = UserData.GetByToken(Token);
|
709
|
string now8 = DateConverter.Instance.DatetimeToDateStrDB8(DateTime.Now);
|
710
|
string now14 = DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now);
|
711
|
lock (obj)
|
712
|
{
|
713
|
IDatabase db = DatabaseFactory.Create();
|
714
|
string EmployeeID = user.EmployeeID;
|
715
|
List<WhereClause> onWhere = new List<WhereClause>();
|
716
|
onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.Equal, TargetValue = now8 });
|
717
|
onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.Equal, TargetValue = now8 });
|
718
|
onWhere.Add(new WhereClause { FieldName = "EmployeeID", Operator = WhereClauseOperator.Equal, TargetValue = EmployeeID });
|
719
|
var existData = db.GetData("PHRPA0019", onWhere).FirstOrDefault();
|
720
|
if (existData != null)
|
721
|
{
|
722
|
msg = GetMessage.GetMessageWithParam("TMABSCEK", user.LangId, "");
|
723
|
}
|
724
|
else
|
725
|
{
|
726
|
#region Insert Attendance
|
727
|
MinovaDataTable ent = new MinovaDataTable(db, "PHRPA0019");
|
728
|
ent.FieldStructure = db.GetTableStructure("PHRPA0019").ToList();
|
729
|
if (ent.DeleteDataRows != null)
|
730
|
{
|
731
|
ent.DeleteDataRows.Clear();
|
732
|
}
|
733
|
if (ent.UpdateDataRows != null)
|
734
|
{
|
735
|
ent.UpdateDataRows.Clear();
|
736
|
}
|
737
|
if (ent.NewDataRows != null)
|
738
|
{
|
739
|
ent.NewDataRows.Clear();
|
740
|
}
|
741
|
Dictionary<string, object> data = new Dictionary<string, object>();
|
742
|
List<Dictionary<string, object>> dataInput = new List<Dictionary<string, object>>();
|
743
|
var todaytime = DateTime.Now.TimeOfDay;
|
744
|
string hour = todaytime.Hours.ToString();
|
745
|
if (hour.Length == 1)
|
746
|
{
|
747
|
hour = "0" + hour;
|
748
|
}
|
749
|
string minute = todaytime.Minutes.ToString();
|
750
|
if (minute.Length == 1)
|
751
|
{
|
752
|
minute = "0" + minute;
|
753
|
}
|
754
|
data.Add("StartDate", now8);
|
755
|
data.Add("EndDate", now8);
|
756
|
data.Add("EmployeeID", user.EmployeeID);
|
757
|
data.Add("StartTime", hour + minute);
|
758
|
data.Add("EndTime", "");
|
759
|
data.Add("AttendanceType", "1000");
|
760
|
data.Add("CreateBy", user.EmployeeID);
|
761
|
data.Add("CreateDate", DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now));
|
762
|
data.Add("ChangeBy", user.EmployeeID);
|
763
|
data.Add("ChangeDate", DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now));
|
764
|
dataInput.Add(data);
|
765
|
ent.NewDataRows = dataInput.ToList();
|
766
|
ent.Save();
|
767
|
#endregion
|
768
|
}
|
769
|
}
|
770
|
}
|
771
|
public void ClockOutAttendance(string Token, ref MinovaMessage msg)
|
772
|
{
|
773
|
UserData user = UserData.GetByToken(Token);
|
774
|
string now8 = DateConverter.Instance.DatetimeToDateStrDB8(DateTime.Now);
|
775
|
string now14 = DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now);
|
776
|
lock (obj)
|
777
|
{
|
778
|
IDatabase db = DatabaseFactory.Create();
|
779
|
string EmployeeID = user.EmployeeID;
|
780
|
List<WhereClause> onWhere = new List<WhereClause>();
|
781
|
onWhere.Add(new WhereClause { FieldName = "StartDate", Operator = WhereClauseOperator.Equal, TargetValue = now8 });
|
782
|
onWhere.Add(new WhereClause { FieldName = "EndDate", Operator = WhereClauseOperator.Equal, TargetValue = now8 });
|
783
|
onWhere.Add(new WhereClause { FieldName = "EmployeeID", Operator = WhereClauseOperator.Equal, TargetValue = EmployeeID });
|
784
|
var existData = db.GetData("PHRPA0019", onWhere).FirstOrDefault();
|
785
|
if (existData == null)
|
786
|
{
|
787
|
msg = GetMessage.GetMessageWithParam("TMABSCEKTIME", user.LangId, "");
|
788
|
}
|
789
|
else
|
790
|
{
|
791
|
if (string.IsNullOrEmpty(existData["EndTime"].ToString()))
|
792
|
{
|
793
|
#region Update EndTime Attendance
|
794
|
MinovaDataTable ent = new MinovaDataTable(db, "PHRPA0019");
|
795
|
ent.FieldStructure = db.GetTableStructure("PHRPA0019").ToList();
|
796
|
if (ent.DeleteDataRows != null)
|
797
|
{
|
798
|
ent.DeleteDataRows.Clear();
|
799
|
}
|
800
|
if (ent.UpdateDataRows != null)
|
801
|
{
|
802
|
ent.UpdateDataRows.Clear();
|
803
|
}
|
804
|
if (ent.NewDataRows != null)
|
805
|
{
|
806
|
ent.NewDataRows.Clear();
|
807
|
}
|
808
|
Dictionary<string, object> data = new Dictionary<string, object>();
|
809
|
List<Dictionary<string, object>> dataInput = new List<Dictionary<string, object>>();
|
810
|
var todaytime = DateTime.Now.TimeOfDay;
|
811
|
string hour = todaytime.Hours.ToString();
|
812
|
if (hour.Length == 1)
|
813
|
{
|
814
|
hour = "0" + hour;
|
815
|
}
|
816
|
string minute = todaytime.Minutes.ToString();
|
817
|
if (minute.Length == 1)
|
818
|
{
|
819
|
minute = "0" + minute;
|
820
|
}
|
821
|
data.Add("StartDate", now8);
|
822
|
data.Add("EndDate", now8);
|
823
|
data.Add("EmployeeID", user.EmployeeID);
|
824
|
data.Add("EndTime", hour + minute);
|
825
|
data.Add("ChangeDate", DateConverter.Instance.DatetimeToDateStrDB14(DateTime.Now));
|
826
|
dataInput.Add(data);
|
827
|
ent.UpdateDataRows = dataInput.ToList();
|
828
|
ent.Save();
|
829
|
#endregion
|
830
|
}
|
831
|
else
|
832
|
{
|
833
|
msg = GetMessage.GetMessageWithParam("TMABSCEKOUT", user.LangId, "");
|
834
|
}
|
835
|
}
|
836
|
}
|
837
|
}
|
838
|
}
|
839
|
}
|