Ejemplo n.º 1
0
        public bool AddWorkingHourToHairSalon(int idHairSalon, WorkingHour addWorkingHour)
        {
            WorkingHour workingHour = unitOfWork.WorkingHours.Get(addWorkingHour.Id);

            HairSalonWorkingHours newHairSalonWorkingHours = new HairSalonWorkingHours()
            {
                HairSalonId = idHairSalon,
                WorkingHour = workingHour
            };

            IEnumerable <HairSalonWorkingHours> hairSalonWorkingHours = unitOfWork.HairSalonWorkingHours.GetHairSalonWorkingHours(idHairSalon);

            foreach (HairSalonWorkingHours hairSalonWorkingHour in hairSalonWorkingHours)
            {
                if (hairSalonWorkingHour.WorkingHourId == workingHour.Id)
                {
                    return(false);
                }
            }

            unitOfWork.HairSalonWorkingHours.Add(newHairSalonWorkingHours);

            int success = unitOfWork.Complete();

            return(success > 0);
        }
Ejemplo n.º 2
0
        public async Task <WorkingHour> UpdateAsync(WorkingHour workingHour)
        {
            var query = new QuerySet();

            query.Include.Fields = new string[] { "invoice", "employee" };
            var existingWorkingHour = await _workingHourDataProvider.GetByIdAsync(workingHour.Id, query);

            if (workingHour.Id != existingWorkingHour.Id)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Working-hour id cannot be updated.");
            }
            if (workingHour.Date == null)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Date is required on working hour.");
            }

            await EmbedRelationsAsync(workingHour, existingWorkingHour);

            if (workingHour.Invoice == null)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice is required.");
            }
            if (workingHour.Employee == null)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Employee is required.");
            }

            return(await _workingHourDataProvider.UpdateAsync(workingHour));
        }
Ejemplo n.º 3
0
        public void Remove(int id)
        {
            WorkingHour workingHour = db.WorkingHour.Find(id);

            db.WorkingHour.Remove(workingHour);
            db.SaveChanges();
        }
Ejemplo n.º 4
0
        public double GetTotalExtraWorkDuration(PersonnelEntrance entrance, WorkingHour workingHour)
        {
            var totalExtraWork = GetPriorExtraWorkDuration(entrance, workingHour)
                                 + GetLaterExtraWorkDuration(entrance, workingHour);

            return(totalExtraWork);
        }
Ejemplo n.º 5
0
        public async Task <int> Create(WorkingHourDTM workingHour)
        {
            try
            {
                WorkingHour iworkingHour = new WorkingHour();
                iworkingHour.MondayStart    = workingHour.MondayStart;
                iworkingHour.MondayStop     = workingHour.MondayStop;
                iworkingHour.TuesdayStart   = workingHour.TuesdayStart;
                iworkingHour.TuesdayStop    = workingHour.TuesdayStop;
                iworkingHour.WednesdayStart = workingHour.WednesdayStart;
                iworkingHour.WednesdayStop  = workingHour.WednesdayStop;
                iworkingHour.ThursdayStart  = workingHour.ThursdayStart;
                iworkingHour.ThursdayStop   = workingHour.ThursdayStop;
                iworkingHour.FridayStart    = workingHour.FridayStart;
                iworkingHour.FridayStop     = workingHour.FridayStop;
                iworkingHour.SaturdayStart  = workingHour.SaturdayStart;
                iworkingHour.SaturdayStop   = workingHour.SaturdayStop;
                iworkingHour.SundayStart    = workingHour.SundayStart;
                iworkingHour.SundayStop     = workingHour.SundayStop;

                iworkingHour.Employee = await Database.Employees.Get(workingHour.EmployeeId);

                await Database.WorkingHours.Create(iworkingHour);

                return(iworkingHour.EmployeeId);
            }
            catch { return(0); }
        }
        public List <WorkingHour> Display(int i)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = ConnectionHelper.getConnectionString();
            conn.Open();

            using (conn)
            {
                SqlCommand command = new SqlCommand("SP_EmployeeHours", conn);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                command.Parameters.Add(new SqlParameter("@empid", i));
                SqlDataReader      reader       = command.ExecuteReader();
                List <WorkingHour> workingHours = new List <WorkingHour>();

                while (reader.Read())
                {
                    WorkingHour workingHour = new WorkingHour();
                    workingHour.WorkingHoursID = Convert.ToInt32(reader["empHoursID"]);
                    workingHour.EmpID          = i;
                    workingHour.Hours          = Convert.ToInt32(reader["Hours"]);
                    workingHour.WorkDate       = Convert.ToDateTime(reader["WorkDate"]).ToString("yyyy-MM-dd");

                    workingHours.Add(workingHour);
                }
                return(workingHours);
            }
        }
        private void btnInsert_Click(object sender, EventArgs e)
        {
            //validate form
            List <hourError> errors = ValidateHours(gbHours);
            //get error messages in string
            string err = GetErrorMsg();

            //print out error messages if found else continue code
            if (err != SUCCESS)
            {
                MessageBox.Show(err);
                tags[0].Focus();
                return;
            }

            //set working hours into hour Working hour class
            WorkingHour hour = new WorkingHour();

            hour.EmpID    = empID;
            hour.Hours    = double.Parse(txtHours.Text);
            hour.WorkDate = txtDate.Text;
            //return the result enum when attempting to insert into DB

            ResultEnum result = Insert(hour);

            if (result == ResultEnum.Success)
            {
                MessageBox.Show("Successfully entered Working Hours");
            }
            else
            {
                MessageBox.Show("An Unexpected Error Occured");
            }
        }
Ejemplo n.º 8
0
        // Embed relations in working-hour resource: reuse old relation if there is one and it hasn't changed
        private async Task EmbedRelationsAsync(WorkingHour workingHour, WorkingHour oldWorkingHour = null)
        {
            try {
                if (oldWorkingHour != null)
                {
                    workingHour.Invoice = oldWorkingHour.Invoice; // invoice cannot be updated. Take invoice of old workingHour on update.
                }
                else
                {
                    workingHour.Invoice = await _invoiceDataProvider.GetByIdAsync(workingHour.Invoice.Id);
                }

                if (oldWorkingHour != null && oldWorkingHour.Employee != null && oldWorkingHour.Employee.Id == oldWorkingHour.Employee.Id)
                {
                    workingHour.Employee = oldWorkingHour.Employee;
                }
                else
                {
                    workingHour.Employee = await _employeeDataProvider.GetByIdAsync(workingHour.Employee.Id);
                }
            }
            catch (EntityNotFoundException)
            {
                _logger.LogDebug($"Failed to find a related entity");
                throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist.");
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> Update(WorkingHourDTM workingHour)
        {
            try
            {
                WorkingHour iworkingHour = new WorkingHour();
                iworkingHour.EmployeeId     = workingHour.EmployeeId;
                iworkingHour.MondayStart    = workingHour.MondayStart;
                iworkingHour.MondayStop     = workingHour.MondayStop;
                iworkingHour.TuesdayStart   = workingHour.TuesdayStart;
                iworkingHour.TuesdayStop    = workingHour.TuesdayStop;
                iworkingHour.WednesdayStart = workingHour.WednesdayStart;
                iworkingHour.WednesdayStop  = workingHour.WednesdayStop;
                iworkingHour.ThursdayStart  = workingHour.ThursdayStart;
                iworkingHour.ThursdayStop   = workingHour.ThursdayStop;
                iworkingHour.FridayStart    = workingHour.FridayStart;
                iworkingHour.FridayStop     = workingHour.FridayStop;
                iworkingHour.SaturdayStart  = workingHour.SaturdayStart;
                iworkingHour.SaturdayStop   = workingHour.SaturdayStop;
                iworkingHour.SundayStart    = workingHour.SundayStart;
                iworkingHour.SundayStop     = workingHour.SundayStop;

                return(await Database.WorkingHours.Update(iworkingHour) ? true : false);
            }
            catch (Exception ex) { Console.Out.WriteLine(ex.Message); return(false); }
        }
 public void Insert(WorkingHour workingHour)
 {
     using (var dbContext = new SoftTehnicaDbContext())
     {
         dbContext.WorkingHours.Add(workingHour);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 11
0
 public static WorkingHourTableRow FromDomainObjects(WorkingHour workingHour)
 {
     return(new WorkingHourTableRow
     {
         Ymd = workingHour.Ymd.Value,
         StartTime = workingHour.StartTime?.ToString("HHmmss") ?? "",
         EndTime = workingHour.EndTime?.ToString("HHmmss") ?? "",
     });
 }
Ejemplo n.º 12
0
        public bool DeleteWorkingHour(int id)
        {
            WorkingHour workingHour = unitOfWork.WorkingHours.Get(id);

            unitOfWork.WorkingHours.Remove(workingHour);

            int success = unitOfWork.Complete();

            return(success > 0);
        }
Ejemplo n.º 13
0
        public string GetOperationTimeFormatted(PersonnelEntrance entrance, WorkingHour workingHour)
        {
            var timeDifference = GetOperationTime(entrance, workingHour);

            if (timeDifference == 0)
            {
                TimeSpan.Zero.ToDetailedString();
            }
            return(SecondsToTimeFormatted(timeDifference));
        }
Ejemplo n.º 14
0
        public async Task <WorkingHour> UpdateAsync(WorkingHour workingHour)
        {
            var workingHourRecord = await FindByIdAsync(workingHour.Id);

            _mapper.Map(workingHour, workingHourRecord);

            _context.WorkingHours.Update(workingHourRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <WorkingHour>(workingHourRecord));
        }
Ejemplo n.º 15
0
        public async Task <WorkingHour> CreateAsync(WorkingHour workingHour)
        {
            var workingHourRecord = _mapper.Map <DataProvider.Models.WorkingHour>(workingHour);

            workingHourRecord.Hours = 1;

            _context.WorkingHours.Add(workingHourRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <WorkingHour>(workingHourRecord));
        }
Ejemplo n.º 16
0
        public EditWorkingHour(WorkingHour workingHour)
        {
            InitializeComponent();

            ls = new LoadingScreen();

            workingHourApi = new WorkingHourApiClient();

            this.workingHour = workingHour;

            SetWorkingHourValues();
        }
Ejemplo n.º 17
0
        public bool EditWorkingHour(WorkingHourEditVM workingHourEditVM)
        {
            WorkingHour workingHour = unitOfWork.WorkingHours.Get(workingHourEditVM.Id);

            workingHour.DayInWeek = workingHourEditVM.DayInWeek;
            workingHour.TimeStart = workingHourEditVM.TimeStart;
            workingHour.TimeEnd   = workingHourEditVM.TimeEnd;

            int success = unitOfWork.Complete();

            return(success > 0);
        }
 public ResultEnum Insert(WorkingHour hour)
 {
     try
     {
         dao.Insert(hour);
         return(ResultEnum.Success);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(ResultEnum.Fail);
     }
 }
Ejemplo n.º 19
0
        public string GetAbsenceTitle(PersonnelEntrance entrance, WorkingHour workingHour)
        {
            if (IsAbsent(entrance))
            {
                return("absence");
            }
            if (GetTotalAbsenceDuration(entrance, workingHour) > 0)
            {
                return("shortage of work time");
            }

            return("-");
        }
Ejemplo n.º 20
0
        public double GetPriorExtraWorkDuration(PersonnelEntrance entrance, WorkingHour workingHour)
        {
            double priorExtraWork = 0;

            if (!IsAbsent(entrance))
            {
                priorExtraWork = (workingHour.FromTime - entrance.Enter).TotalSeconds > 0
                        ? (workingHour.FromTime - entrance.Enter).TotalSeconds : 0;
            }

            return(priorExtraWork > workingHour.PriorExtraWorkTime
                ? workingHour.PriorExtraWorkTime : priorExtraWork);
        }
Ejemplo n.º 21
0
 public string GetTotalExtraWorkTitle(double priorExtraWorkDuration
                                      , double laterExtraWorkDuration, WorkingHour workingHour)
 {
     if (laterExtraWorkDuration > workingHour.LaterExtraWorkTime)
     {
         return("not authorized last extra work");
     }
     if (priorExtraWorkDuration > workingHour.PriorExtraWorkTime)
     {
         return("not authorized first extra work");
     }
     return("-");
 }
Ejemplo n.º 22
0
        public WorkingHourPanel(WorkingHour workingHour, HairSalon hairSalon)
        {
            InitializeComponent();

            ls = new LoadingScreen();

            workingHourApi           = new WorkingHourApiClient();
            hairSalonWorkingHoursApi = new HairSalonWorkingHoursApiClient();

            this.workingHour = workingHour;
            this.hairSalon   = hairSalon;

            SetWorkingHourValues();
        }
Ejemplo n.º 23
0
        public void saveWorkinHour(object sender, EventArgs e)
        {
            WorkingHour workingHour = new WorkingHour(hour.Text, Int32.Parse(duration.Text), description.Text);

            if (workingHourBusiness.insertNewWorkingHour(workingHour))
            {
                Response.Redirect(Utility.WORKING_HOURS_PAGE);
            }
            else
            {
                dangerAlert.Visible     = true;
                alertDangerMessage.Text = "No se ha podido ingresar";
            }
        }
Ejemplo n.º 24
0
        public ActionResult Create(IFormCollection collection)
        {
            if (getCurrentUser() == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                try
                {
                    if (Convert.ToDecimal(collection["wh_hours"]) > 0)
                    {
                        decimal workinghour = ioverTimeRequest.getWorkingHourByDocument(Convert.ToInt32(collection["id"]),
                                                                                        Convert.ToInt32(collection["doc_id"]));
                        decimal additionalworkinghour = iworkingHour.GetWorkingHourConsolidateByDocument(Convert.ToInt32(collection["id"]),
                                                                                                         Convert.ToInt32(collection["doc_id"]));
                        decimal totalexpected = additionalworkinghour + Convert.ToDecimal(collection["wh_hours"]);

                        ViewBag.workingHour = Math.Round(workinghour, 2);
                        ViewBag.deduction   = Math.Round(additionalworkinghour, 2);
                        if ((workinghour - totalexpected) >= 0)
                        {
                            WorkingHour workingHour = new WorkingHour();
                            workingHour.wh_fun_doc_id = Convert.ToInt32(collection["id"]);
                            workingHour.wh_doc_id     = Convert.ToInt32(collection["doc_id"]);
                            workingHour.wh_remarks    = Convert.ToString(collection["wh_remarks"]);
                            workingHour.wh_hours      = Convert.ToDecimal(collection["wh_hours"]);
                            workingHour.wh_cre_by     = getCurrentUser().u_id;
                            workingHour.wh_cre_date   = DateTime.Now;
                            iworkingHour.Add(workingHour);
                        }
                        else
                        {
                            TempData["errorMessage"] = "Deduction amount greater than actual Working hour!! " + (workinghour - totalexpected);
                        }
                    }
                    else
                    {
                        TempData["errorMessage"] = "Deduction cannot be Zero!!";
                    }
                }catch (Exception ex)
                {
                    TempData["errorMessage"] = "Error:" + ex.Message;
                }


                return(View(iworkingHour.GetWorkingHourByDocument(Convert.ToInt32(collection["id"]), Convert.ToInt32(collection["doc_id"]))));
            }
        }
Ejemplo n.º 25
0
        public bool InsertWorkingHour(WorkingHourInsertVM workingHourInsertVM)
        {
            WorkingHour workingHour = new WorkingHour()
            {
                DayInWeek = workingHourInsertVM.DayInWeek,
                TimeStart = workingHourInsertVM.TimeStart,
                TimeEnd   = workingHourInsertVM.TimeEnd
            };

            unitOfWork.WorkingHours.Add(workingHour);

            int success = unitOfWork.Complete();

            return(success > 0);
        }
        public async Task <bool> AddWorkingHourToHairSalon(int idHairSalon, WorkingHour workingHour)
        {
            StringContent content = GetStringContent(workingHour);
            HttpClient    request = new HttpClient();

            HttpResponseMessage response = await request.PostAsync($"{ API_URL }/AddWorkingHourToHairSalon/{ idHairSalon }", content);

            if (response.IsSuccessStatusCode)
            {
                bool result = await response.Content.ReadAsAsync <bool>();

                return(result);
            }
            return(false);
        }
Ejemplo n.º 27
0
        public IEnumerable <IResource> CollectIncluded(WorkingHour workingHour, IncludeQuery includeQuery)
        {
            ISet <IResource> included = new HashSet <IResource>();

            // one-relations
            if (includeQuery.Contains("employee") && workingHour.Employee != null)
            {
                included.Add(_mapper.Map <EmployeeDto>(workingHour.Employee));
            }
            if (includeQuery.Contains("invoice") && workingHour.Invoice != null)
            {
                included.Add(_mapper.Map <InvoiceDto>(workingHour.Invoice));
            }

            return(included);
        }
Ejemplo n.º 28
0
        public async Task <int> Create(EmployeeDTM item)
        {
            try
            {
                Employee employee = new Employee();
                employee.Business = await Database.Businesses.Get(item.Business.Id);

                employee.BusinessId = item.Business.Id;
                employee.User       = await Database.Users.Get(item.User.Id);

                employee.UserId  = item.User.Id;
                employee.IsOwner = item.IsOwner;

                await Database.Employees.Create(employee);

                if (employee.IsOwner == false)
                {
                    WorkingHour wHourDtm = new WorkingHour();
                    wHourDtm.Employee   = employee;
                    wHourDtm.EmployeeId = employee.Id;
                    await Database.WorkingHours.Create(wHourDtm);

                    Permission perm = new Permission();
                    perm.Employee   = employee;
                    perm.EmployeeId = employee.Id;
                    await Database.Permissions.Create(perm);

                    CalendarSetting cSetting = new CalendarSetting();
                    cSetting.Employee   = employee;
                    cSetting.EmployeeId = employee.Id;
                    await Database.CalendarSettings.Create(cSetting);

                    CustomerNotification cNotif = new CustomerNotification();
                    cNotif.Employee   = employee;
                    cNotif.EmployeeId = employee.Id;
                    await Database.CustomerNotifications.Create(cNotif);

                    TeamNotification tNotif = new TeamNotification();
                    tNotif.Employee   = employee;
                    tNotif.EmployeeId = employee.Id;
                    await Database.TeamNotifications.Create(tNotif);
                }

                return(employee.Id);
            }
            catch { return(0); }
        }
Ejemplo n.º 29
0
        private double CalcOperationTime(PersonnelEntrance entrance, WorkingHour workingHour)
        {
            if (!entrance.ExitDate.HasValue || !entrance.Exit.HasValue)
            {
                return(0);
            }
            var exit = entrance.Exit.Value <= workingHour.ToTime ? entrance.Exit.Value
                    : workingHour.ToTime;
            var enter = entrance.Enter >= workingHour.FromTime ? entrance.Enter
                : workingHour.FromTime;

            var exitDate  = entrance.ExitDate.Value.Date.Add(exit);
            var enterDate = entrance.EnterDate.Date.Add(enter);

            return((exitDate - enterDate).TotalSeconds
                   - GetWorkingHourBreakTimes(entrance, workingHour));
        }
Ejemplo n.º 30
0
        public static Employee changeFromDTM(EmployeeDTM employeeDtm)
        {
            Employee employee = new Employee();

            employee.Id         = employeeDtm.Id;
            employee.Business   = changeFromDTM(employeeDtm.Business);
            employee.BusinessId = employeeDtm.Business.Id;
            employee.User       = changeFromDTM(employeeDtm.User);
            employee.UserId     = employeeDtm.User.Id;
            employee.IsOwner    = employeeDtm.IsOwner;

            if (employeeDtm.CalendarSetting != null)
            {
                CalendarSetting cset = new CalendarSetting();
                cset = changeFromDTM(employeeDtm.CalendarSetting);
                employee.CalendarSetting = cset;
            }
            if (employeeDtm.CustomerNotification != null)
            {
                CustomerNotification cNotice = new CustomerNotification();
                cNotice = changeFromDTM(employeeDtm.CustomerNotification);
                employee.CustomerNotification = cNotice;
            }
            if (employeeDtm.TeamNotification != null)
            {
                TeamNotification tNotice = new TeamNotification();
                tNotice = changeFromDTM(employeeDtm.TeamNotification);
                employee.TeamNotification = tNotice;
            }
            if (employeeDtm.Permission != null)
            {
                Permission permission = new Permission();
                permission          = changeFromDTM(employeeDtm.Permission);
                employee.Permission = permission;
            }
            if (employeeDtm.WorkingHour != null)
            {
                WorkingHour wHour = new WorkingHour();
                wHour = changeFromDTM(employeeDtm.WorkingHour);
                employee.WorkingHour = wHour;
            }

            return(employee);
        }