Untitled

 avatar
unknown
plain_text
a month ago
8.2 kB
3
Indexable
 case "CEBU_GLASCRAFTER":
                                    try
                                    {
                                        // list of employee logs per day
                                        List<EmployeeLogViewModel> listDataLogs = new List<EmployeeLogViewModel>();

                                        var companyID = user.CompanyId;

                                        using (var sr = new StreamReader(filepath))
                                        {
                                            string s = string.Empty;
                                            while ((s = sr.ReadLine()) != null)
                                            {

                                                // store to log 
                                                EmployeeLogViewModel datalog = new EmployeeLogViewModel();
                                                string[] readLine = s.Split('\t');
                                                // remove empty values in a element
                                                readLine = readLine.Where(value => !string.IsNullOrEmpty(value)).ToArray();
                                                // 1st col
                                                var empID = readLine[0].Replace(" ", ""); // remove spacing base on raw format

                                                // check first if employee id exist in db if not continue
                                                var empData = _employeeService.FindByEmployeeIDandCompanyId(empID, user.CompanyId);

                                                // continue loop if employee not exist
                                                if (empData == null)
                                                {
                                                    continue;
                                                }

                                                // logs if employee has no shift
                                                // add logic when shift value is null add it to logs
                                                if (!EmployeeHasShift(empData))
                                                {
                                                    continue;
                                                }

                                                // split datetime and timelog
                                                // 2nd col
                                                string[] dateLog = readLine[1].Split(' '); // split date and logs
                                                var dateTimestr = dateLog[0];
                                                var timeLogstr = dateLog[1];

                                                //4th status
                                                // TIME-IN - 0,
                                                // BREAKSTART - 1,
                                                // BREAKEND - 0,
                                                // TIME-OUT - 1,
                                                var logStatus = readLine[3];
                                                // store to view model per row line/logs
                                                // 6 fields per row line logs
                                                // sample row line logs -- EmployeeID, datetime,0,0,0,0
                                                // status log:

                                                datalog.EmployeeID = empID; 
                                                datalog.TimelogDate = dateTimestr;
                                                if(CheckEmplogExist(listDataLogs, datalog))
                                                {
                                                    // check statuslogs
                                                    // parameter EmployeeLog, timein, statusno
                                                    GetEmployeeLog(listDataLogs, datalog, logStatus, timeLogstr);

                                                } else
                                                {
                                                    // store very first log base on scenario 11 and 12
                                                    // file: Timecard_Scenarios.txt
                                                    if (Convert.ToInt32(logStatus) == Constants.Timelogs.StatusIN)
                                                    {
                                                        datalog.TimeIn = timeLogstr;
                                                    } else
                                                    {
                                                        // status out
                                                        datalog.BreakStart = timeLogstr;
                                                    }
                                                    listDataLogs.Add(datalog);
                                                
                                                }
                                            }
                                        }
                                        int startRow = 0;
                                        int rowCounter = 0; // employee counter if not found insert to logs
                                        // check if employee log exists in employee201

                                        var employees = _employeeService.CompanyEmployeeList(companyID);
                                        foreach (EmployeeLogViewModel employLog in listDataLogs)
                                        {

                                            var empData = _employeeService.FindByEmployeeIDandCompanyId(employLog.EmployeeID, user.CompanyId);

                                            Shift shift = new Shift();

                                            shift = _shiftService.Find(empData.UserMaster.ShiftID.Value);

                                            DateTime timeLogDate = DateTime.Parse(employLog.TimelogDate);

                                            if (isShiftStartGreaterThanTimelog(shift, timeLogDate))
                                            {
                                                continue;
                                            }
                                            rowCounter++;
                                            Dictionary<string, object> data = StoreEmployeelogToDictionary(companyID, employLog);
                                            // row counter
                                            startRow++;
                                            var validationResult = validatorDelegate(data, startRow);
                                            if (validationResult.ConversionError.Count > 0)
                                            {
                                                sheetReaderViewModel.FailedReadLines.AddRange(validationResult.ConversionError);
                                                using (StreamWriter sw = File.AppendText(Constants.Timelogs.logErrorFilePath))
                                                {
                                                    sw.WriteLine($"{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}");
                                                    sw.WriteLine(Constants.Timelogs.statusLabel + " " + startRow + validationResult.ConversionError);
                                                    sw.WriteLine(Constants.Timelogs.logFileHorizontalLine);
                                                }
                                            }
                                            else
                                            {
                                                sheetReaderViewModel.SucceededReadLines.Add(validationResult.ConvertedEntity);
                                            }
                                        }
                                    }
Leave a Comment