public int?CreateUpdateGuardPayment(GuardPaymentViewModel guardPaymentViewModel)
        {
            GuardPayment guardPayment = null;

            if (guardPaymentViewModel.GuardPaymentId > 0)
            {
                guardPayment = _repository.Find <GuardPayment>(x => x.GuardPaymentId == guardPaymentViewModel.GuardPaymentId);
                if (guardPayment == null)
                {
                    return(null);
                }

                guardPayment.GuardId      = guardPaymentViewModel.GuardId;
                guardPayment.PaymentDate  = guardPaymentViewModel.PaymentDate;
                guardPayment.StartDate    = guardPaymentViewModel.StartDate;
                guardPayment.EndDate      = guardPaymentViewModel.EndDate;
                guardPayment.Amount       = guardPaymentViewModel.Amount;
                guardPayment.TotalHours   = guardPaymentViewModel.TotalHours;
                guardPayment.HourlyRate   = guardPaymentViewModel.HourlyRate;
                guardPayment.Comments     = guardPaymentViewModel.Comments;
                guardPayment.ModifiedBy   = guardPaymentViewModel.ModifiedBy;
                guardPayment.ModifiedDate = DateTime.Now;

                _repository.Modify <GuardPayment>(guardPayment);
                return(guardPayment.GuardPaymentId);
            }

            Mapper.CreateMap <GuardPaymentViewModel, GuardPayment>();
            guardPayment = Mapper.Map <GuardPaymentViewModel, GuardPayment>(guardPaymentViewModel);

            guardPayment.CreatedDate = DateTime.Now;
            guardPayment.CreatedBy   = guardPaymentViewModel.CreatedBy;
            guardPayment.IsDeleted   = false;
            return(_repository.Insert <GuardPayment>(guardPayment));
        }
        public ActionResult CreateUpdateGuardPayment(GuardPaymentViewModel guardPaymentViewModel)
        {
            ActiveUser activeUser = new JavaScriptSerializer().Deserialize <ActiveUser>(System.Web.HttpContext.Current.User.Identity.Name);

            guardPaymentViewModel.CreatedBy  = activeUser.UserId;
            guardPaymentViewModel.ModifiedBy = activeUser.UserId;

            var result = _guardPaymentComponent.CreateUpdateGuardPayment(guardPaymentViewModel);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateUpdateGuardPaymentPopup(int id)
        {
            var guardPayment = _guardPaymentComponent.GetGuardPayment(id);

            if (guardPayment == null)
            {
                guardPayment = new GuardPaymentViewModel();
            }
            guardPayment.GuardList = new SelectList(_guardComponent.GetAllGaurd(), "GuardId", "NameSSN");
            //customerPayment.InvoiceList = new SelectList(_customerInvoiceComponent.GetAllCustomerInvoice(), "InvoiceId", "InvoiceNo");
            return(PartialView("/Views/Shared/Partials/_GuardPayment.cshtml", guardPayment));
        }
        public ActionResult GetPaymentAmount(string startDate, string endDate, int guardId)
        {
            GuardPaymentViewModel objectGuardPaymentViewModel = _guardPaymentComponent.GetPaymentAmount(startDate, endDate, guardId);
            string beginDateDay   = (objectGuardPaymentViewModel.StartDate.Day.ToString().Length == 1) ? "0" + objectGuardPaymentViewModel.StartDate.Day.ToString() : objectGuardPaymentViewModel.StartDate.Day.ToString();
            string beginDateMonth = (objectGuardPaymentViewModel.StartDate.Month.ToString().Length == 1) ? "0" + objectGuardPaymentViewModel.StartDate.Month.ToString() : objectGuardPaymentViewModel.StartDate.Month.ToString();
            string endDateDay     = (objectGuardPaymentViewModel.EndDate.Day.ToString().Length == 1) ? "0" + objectGuardPaymentViewModel.EndDate.Day.ToString() : objectGuardPaymentViewModel.EndDate.Day.ToString();
            string endDateMonth   = (objectGuardPaymentViewModel.EndDate.Month.ToString().Length == 1) ? "0" + objectGuardPaymentViewModel.EndDate.Month.ToString() : objectGuardPaymentViewModel.EndDate.Month.ToString();

            return(Json(new
            {
                StartDate = objectGuardPaymentViewModel.StartDate.Year + "-" + beginDateMonth + "-" + beginDateDay,
                EndDate = objectGuardPaymentViewModel.EndDate.Year + "-" + endDateMonth + "-" + endDateDay,
                TotalHours = objectGuardPaymentViewModel.TotalHours,
                Amount = objectGuardPaymentViewModel.Amount,
                HourlyRate = objectGuardPaymentViewModel.HourlyRate
            }, JsonRequestBehavior.AllowGet));
        }
        public GuardPaymentViewModel GetPaymentAmount(string startDate, string endDate, int guardId)
        {
            using (SecurityAgencyEntities objContext = new SecurityAgencyEntities())
            {
                DateTime _startDate = Convert.ToDateTime(startDate);
                DateTime _endDate   = Convert.ToDateTime(endDate);
                //Get Guard Hourly Rate
                //GuardHourlyRate objectGuardHourlyRate = _repository.GetAll<GuardHourlyRate>().Where(x => x.GuardId == guardId).OrderByDescending(i => i.HourlyRateId).FirstOrDefault();
                //Get Last Start and End Date
                GuardPayment objectGuardPayment = objContext.GuardPayments.Where(i => i.GuardId == guardId && i.IsDeleted == false).OrderByDescending(i => i.EndDate).FirstOrDefault();
                Guard        objectGuard        = objContext.Guards.Where(i => i.GuardId == guardId).FirstOrDefault();
                if (objectGuardPayment != null)
                {
                    _startDate = objectGuardPayment.EndDate;
                    _endDate   = objectGuardPayment.EndDate.AddDays(7);
                }
                List <GuardPaymentViewModel> guardPaymentViewModel = (from dailyLog in objContext.DailyLogs
                                                                      where (dailyLog.Dated > _startDate && dailyLog.Dated < _endDate) &&
                                                                      (dailyLog.IsDeleted == false) &&
                                                                      dailyLog.GuardId == guardId
                                                                      select new GuardPaymentViewModel
                {
                    TotalHours = dailyLog.Hours,
                }).ToList();

                if (guardPaymentViewModel == null)
                {
                    return(null);
                }

                GuardPaymentViewModel objectGuardPaymentViewModel = new GuardPaymentViewModel();
                objectGuardPaymentViewModel.HourlyRate = objectGuard.HourlyRate;
                objectGuardPaymentViewModel.TotalHours = guardPaymentViewModel.Sum(i => i.TotalHours);
                objectGuardPaymentViewModel.Amount     = objectGuardPaymentViewModel.TotalHours * objectGuard.HourlyRate;
                objectGuardPaymentViewModel.StartDate  = _startDate;
                objectGuardPaymentViewModel.EndDate    = _endDate;
                return(objectGuardPaymentViewModel);
            }
        }