Exemple #1
0
        public BiometryCalculatedDetail CalculateTotal(List <BiometryCalculatedDetail> taradodInfo)
        {
            var bioDetail = new BiometryCalculatedDetail();

            foreach (var detail in taradodInfo)
            {
                bioDetail.Total         += detail.Total;
                bioDetail.TotalValid    += GetTotal(detail.Times, BiometryCalculatedDetailTimeType.Valid);
                bioDetail.TotalAbsence  += GetTotal(detail.Times, BiometryCalculatedDetailTimeType.Absence);
                bioDetail.InValid       += GetTotal(detail.Times, BiometryCalculatedDetailTimeType.NotValid);
                bioDetail.TotalOvertime += GetTotal(detail.Times, BiometryCalculatedDetailTimeType.Overtime);

                bioDetail.TotalStr         = EngineUtility.ConvertTimeSpanToStr(bioDetail.Total);
                bioDetail.TotalValidStr    = EngineUtility.ConvertTimeSpanToStr(bioDetail.TotalValid);
                bioDetail.TotalAbsenceStr  = EngineUtility.ConvertTimeSpanToStr(bioDetail.TotalAbsence);
                bioDetail.InValidStr       = EngineUtility.ConvertTimeSpanToStr(bioDetail.InValid);
                bioDetail.TotalOvertimeStr = EngineUtility.ConvertTimeSpanToStr(bioDetail.TotalOvertime);

                bioDetail.VacationStr    = EngineUtility.ConvertTimeSpanToStr(bioDetail.Vacation);
                bioDetail.HolidayWorkStr = EngineUtility.ConvertTimeSpanToStr(bioDetail.HolidayWork);
                bioDetail.MissionWorkStr = EngineUtility.ConvertTimeSpanToStr(bioDetail.MissionWork);
                bioDetail.NightWorkStr   = EngineUtility.ConvertTimeSpanToStr(bioDetail.NightWork);
                bioDetail.ShiftWorkStr   = EngineUtility.ConvertTimeSpanToStr(bioDetail.ShiftWork);

                /*bioDetail.DateStr =
                 *  Engine.Controllers.AbstractControllers.Utility
                 *      .ConvertToShamsiDate(bioDetail.Date, false, true);*/
                bioDetail.ShiftWorkStr = EngineUtility.ConvertTimeSpanToStr(bioDetail.ShiftWork);
            }

            return(bioDetail);
        }
        public void TimeSpanToStrTest()
        {
            var time = new DateTime(2017, 05, 05, 2, 50, 58);
            // var c = new PersonnelTaradodInfoService();

            var str = EngineUtility.ConvertTimeSpanToStr(time.TimeOfDay);

            Assert.True(str == "2:50:58");
        }
        public List <PersonnelClockStatusViewModel> GetAll(ObjectPostViewModel vm)
        {
            if (vm == null || vm.obj == null)
            {
                throw new Exception("اطلاعات ارسالی نال است");
            }

            using (var db = new EngineContext())
            {
                var workplacePersonnel = GetWorkplacePersonnelFromToken(db, vm.token);

                // پرسنل هایی که در آن گروه کاری هستند
                var dt = db.WorkplacePersonnels.Where(w => w.WorkplaceId == workplacePersonnel.WorkplaceId);



                //فقط خودش
                if (!workplacePersonnel.IsAdmin)
                {
                    dt = dt.Where(d => d.PersonnelId == workplacePersonnel.PersonnelId);
                }

                var dates = dt.SelectMany(d => d.BiometricDatas
                                          .Where(day => day.Date.Year == DateTime.Now.Year &&
                                                 day.Date.Month == DateTime.Now.Month &&
                                                 day.Date.Day == DateTime.Now.Day)).OrderBy(d => d.Date);


                List <PersonnelClockStatusViewModel> list = new List <PersonnelClockStatusViewModel>();

                foreach (var biometricData in dates)
                {
                    if (vm.obj == null || vm.obj as long? == 0)
                    {
                        // قسمت داشبورد
                        var time = biometricData.BiometricDataTimes.OrderBy(d => d.InsertDateTime).LastOrDefault();
                        list.Add(new PersonnelClockStatusViewModel
                        {
                            lastClockIn = time != null && time.TimeIn.HasValue
                                ? EngineUtility.ConvertTimeSpanToStr(time.TimeIn.Value.TimeOfDay)
                                : "-",
                            lastClockOut = time != null && time.TimeOut.HasValue
                                ? EngineUtility.ConvertTimeSpanToStr(time.TimeOut.Value.TimeOfDay)
                                : "-",
                            name = biometricData.WorkplacePersonnel.Personnel.Name + " " +
                                   biometricData.WorkplacePersonnel.Personnel.LastName,
                            status      = GetStatus(time),
                            color       = GetColor(time),
                            personnelId = biometricData.WorkplacePersonnel.Personnel.Id
                        });
                    }
                    else
                    {
                        // قسمت جزئیات تردد پرسنل
                        var ordered = biometricData.BiometricDataTimes.OrderBy(d => d.InsertDateTime);
                        foreach (var time in ordered)
                        {
                            list.Add(new PersonnelClockStatusViewModel
                            {
                                lastClockIn = time != null && time.TimeIn.HasValue
                               ? EngineUtility.ConvertTimeSpanToStr(time.TimeIn.Value.TimeOfDay)
                               : "-",
                                lastClockOut = time != null && time.TimeOut.HasValue
                               ? EngineUtility.ConvertTimeSpanToStr(time.TimeOut.Value.TimeOfDay)
                               : "-",
                                name = biometricData.WorkplacePersonnel.Personnel.Name + " " +
                                       biometricData.WorkplacePersonnel.Personnel.LastName,
                                status      = GetStatus(time),
                                color       = GetColor(time),
                                personnelId = biometricData.WorkplacePersonnel.Personnel.Id
                            });
                        }
                    }
                }

                return(list);
            }
        }
Exemple #4
0
        public async Task <ClockInViewModelResult> ClockIn(ClockInViewModel vm)
        {
            try
            {
                using (var db = new EngineContext())
                {
                    string username = SecurityService.GetUsernameFromToken(vm.token);


                    //یافتن پرسنل
                    var workplacePersonnel = db.WorkplacePersonnels.FirstOrDefault(p => p.Username == username);
                    if (workplacePersonnel == null)
                    {
                        throw new Exception("کاربر یافت نشد");
                    }


                    // کلاک ورود
                    // آیا قبلا وارد شده است
                    var biometricDate =
                        db.BiometricDatas.FirstOrDefault(b =>
                                                         b.WorkplacePersonnelId == workplacePersonnel.Id &&
                                                         b.Date.Year == DateTime.Now.Year &&
                                                         b.Date.Month == DateTime.Now.Month &&
                                                         b.Date.Day == DateTime.Now.Day
                                                         );

                    if (biometricDate == null)
                    {
                        biometricDate = db.BiometricDatas.Create();
                    }

                    var lastBiometricDateTime =
                        biometricDate.BiometricDataTimes.OrderBy(d => d.InsertDateTime).LastOrDefault();


                    string clocktypestr = "وارد";
                    if (lastBiometricDateTime == null ||
                        (lastBiometricDateTime.TimeIn.HasValue && lastBiometricDateTime.TimeOut.HasValue))
                    {
                        var clocktypes = workplacePersonnel.Workplace.UserClockTypes;

                        // ولیدیشن نوع کلاک ها
                        ValidateClocks(clocktypes, vm, workplacePersonnel, db);

                        // هیچ کلاکی نزده است
                        lastBiometricDateTime        = db.BiometricDataTimes.Create();
                        lastBiometricDateTime.TimeIn = DateTime.Now;
                        lastBiometricDateTime.ClockInViewModels.Add(vm);


                        //ذخیره
                        biometricDate.BiometricDataTimes.Add(lastBiometricDateTime);
                        workplacePersonnel.BiometricDatas.Add(biometricDate);

                        db.Entry(workplacePersonnel).State = EntityState.Modified;


                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        // throw new Exception("شما قبلا ساعت ورود زده اید");

                        if (lastBiometricDateTime.TimeOut.HasValue)
                        {
                            throw new Exception("شما قبلا ساعت خروج زده اید");
                        }

                        // هیچ کلاکی نزده است
                        lastBiometricDateTime.TimeOut = DateTime.Now;

                        //ذخیره

                        db.Entry(lastBiometricDateTime).State = EntityState.Modified;
                        clocktypestr = "خارج";
                        await db.SaveChangesAsync();
                    }


                    var hour = EngineUtility.ConvertTimeSpanToStr(lastBiometricDateTime.TimeIn.Value.TimeOfDay);
                    return(await Task.FromResult(new ClockInViewModelResult
                    {
                        success = true,
                        message = $@" {clocktypestr } در {hour} "
                    }));
                }
            }
            catch (Exception e)
            {
                return(await Task.FromResult(new ClockInViewModelResult
                {
                    success = false,
                    message = e.Message
                }));

                throw;
            }
        }