Пример #1
0
        public ActionResult GetWeekTimesheetSummary(Guid id)
        {
            TimesheetSummaryDTO val = null;

            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                Task <String> response = httpClient.GetStringAsync("api/TimesheetAPI/GetTimesheetSummary/" + id.ToString());
                val = Task.Factory.StartNew(() => JsonConvert.DeserializeObject <TimesheetSummaryDTO>(response.Result)).Result;
            }

            return(PartialView("_TimesheetSummaryPartial", val));
        }
Пример #2
0
 public JsonResult ApproveTimesheet(TimesheetSummaryDTO model)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         var responseMessage = httpClient.PostAsJsonAsync("/api/TimesheetAPI/ApproveTimesheet", model.Id).Result;
         if (responseMessage.IsSuccessStatusCode)
         {
             return(Json(new { success = "true", message = "Thanks" }));
         }
         else
         {                                                                     //If and error occurred add details to model error.
             var error = JsonConvert.DeserializeObject <System.Web.Http.HttpError>(responseMessage.Content.ReadAsStringAsync().Result);
             return(Json(new { success = "false", message = error.Message })); // do a concatenation of the model state errors
         }
     }
 }
Пример #3
0
        public TimesheetSummaryDTO GetTimesheetSummary(Guid id)
        {
            if (Is <TimesheetFeature> .Enabled)
            {
                TimesheetSummaryDTO timesheetSummaryDto = new TimesheetSummaryDTO();

                Timesheet timesheet = db.Timesheets.Find(id);
                if (timesheet == null)
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                if (ClaimsAuthorization.CheckAccess("Put", "BusinessId", timesheet.Roster.BusinessLocation.Business.Id.ToString()))
                {
                    DateTime weekStart = timesheet.Roster.WeekStartDate;
                    DateTime weekEnd   = weekStart.AddDays(7);

                    timesheetSummaryDto.WeekStartDate = weekStart;

                    Decimal  totalCost      = new decimal();
                    TimeSpan totalShiftTime = new TimeSpan();

                    //Get all timecard entries which have a clock in date time within the Timesheets roster week
                    var timecards = db.TimeCards.Where(tc => tc.BusinessLocation.Id == timesheet.Roster.BusinessLocation.Id && weekStart <= tc.ClockIn && tc.ClockIn < weekEnd);
                    timesheetSummaryDto.AllTimeCardsApproved = true;
                    foreach (var timecard in timecards)
                    {
                        timesheetSummaryDto.TotalShifts++;

                        if (!timecard.TimesheetEntry.Approved)
                        {
                            timesheetSummaryDto.AllTimeCardsApproved = false;
                        }
                        else
                        {
                            var timeSpan = timecard.TimesheetEntry.FinishDateTime - timecard.TimesheetEntry.StartDateTime;
                            if (timeSpan.HasValue)
                            {
                                totalShiftTime = totalShiftTime.Add(timeSpan.Value);
                                var shiftCost = (decimal)timeSpan.Value.TotalHours * timecard.Employee.PayRate.GetValueOrDefault();
                                totalCost += shiftCost;
                            }
                        }
                    }

                    timesheetSummaryDto.TotalHours    = totalShiftTime.TotalHours;
                    timesheetSummaryDto.TotalCost     = totalCost;
                    timesheetSummaryDto.AvgHourlyRate = totalCost / (decimal)totalShiftTime.TotalHours;

                    return(timesheetSummaryDto);
                }
                else
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotImplemented));
            }
        }