public ActionResult CreateCustomerInvoice(CustomerInvoiceViewModel customerViewModel)
        {

            ActiveUser activeUser = new JavaScriptSerializer().Deserialize<ActiveUser>(System.Web.HttpContext.Current.User.Identity.Name);
            customerViewModel.CreatedBy = activeUser.UserId;
            customerViewModel.ModifiedBy = activeUser.UserId;

            var result = _customerInvoiceComponent.CreateCustomerInvoice(customerViewModel);

            return Json(result, JsonRequestBehavior.AllowGet);

        }
 public ActionResult CreateCustomerInvoicePopup(int id)
 {
     var customer = _customerInvoiceComponent.GetCustomerInvoice(id);
     if (customer == null)
         customer = new CustomerInvoiceViewModel();
     customer.CustomerList = new SelectList(_customerComponent.GetAllCustomer(), "CustomerId", "NameEmail");
     return PartialView("/Views/Shared/Partials/_CustomerInvoice.cshtml", customer);
 }
        public int? CreateCustomerInvoice(CustomerInvoiceViewModel customerInvoiceViewModel)
        {
            CustomerInvoice customerInvoice = null;

            if (customerInvoiceViewModel.InvoiceId > 0)
            {
                customerInvoice = _repository.Find<CustomerInvoice>(x => x.InvoiceId == customerInvoiceViewModel.InvoiceId);
                if (customerInvoice == null)
                    return null;

                customerInvoice.CustomerId = customerInvoiceViewModel.CustomerId;
                customerInvoice.InvoiceNo = customerInvoiceViewModel.InvoiceNo;
                customerInvoice.BeginDate = customerInvoiceViewModel.BeginDate;
                customerInvoice.EndDate = customerInvoiceViewModel.EndDate;
                customerInvoice.TotalHours = customerInvoiceViewModel.TotalHours;
                customerInvoice.HourlyRate = customerInvoiceViewModel.HourlyRate;
                customerInvoice.Amount = customerInvoiceViewModel.Amount;
                customerInvoice.Description = customerInvoiceViewModel.Description;
                customerInvoice.InternalComments = customerInvoiceViewModel.InternalComments;
                customerInvoice.ModifiedBy = customerInvoiceViewModel.ModifiedBy;
                customerInvoice.ModifiedDate = DateTime.Now;

                _repository.Modify<CustomerInvoice>(customerInvoice);
                return customerInvoice.InvoiceId;
            }

            Mapper.CreateMap<CustomerInvoiceViewModel, CustomerInvoice>();
            customerInvoice = Mapper.Map<CustomerInvoiceViewModel, CustomerInvoice>(customerInvoiceViewModel);

            customerInvoice.CreatedDate = DateTime.Now;
            customerInvoice.CreatedBy = customerInvoiceViewModel.CreatedBy;
            customerInvoice.IsDeleted = false;
            return _repository.Insert<CustomerInvoice>(customerInvoice);
        }
        public CustomerInvoiceViewModel GenerateInvoice(int invoiceId)
        {
            using (SecurityAgencyEntities objContext = new SecurityAgencyEntities())
            {
                CustomerInvoiceViewModel objectCustomerInvoiceViewModel = new CustomerInvoiceViewModel();
                objectCustomerInvoiceViewModel = (from customer in objContext.Customers
                                                  join customerInvoice in objContext.CustomerInvoices on customer.CustomerId equals customerInvoice.CustomerId
                                                  where customerInvoice.InvoiceId == invoiceId
                                                  select new CustomerInvoiceViewModel
                                                  {
                                                      InvoiceNo = customerInvoice.InvoiceNo,
                                                      Name = customer.Name,
                                                      HourlyRate=customerInvoice.HourlyRate,
                                                      Address = customer.Address,
                                                      Zip = customer.Zip,
                                                      ContactNo = customer.ContactNo,
                                                      InvoiceDate = customerInvoice.InvoiceDate,
                                                      TotalHours = customerInvoice.TotalHours,
                                                      Description = customerInvoice.Description,
                                                      Amount = customerInvoice.Amount,
                                                      BeginDate = customerInvoice.BeginDate,
                                                      EndDate = customerInvoice.EndDate,
                                                      CustomerId = customerInvoice.CustomerId
                                                  }).FirstOrDefault();

                //////Get values from hourlog table
                List<getCustomerInvoiceAmount_Result> objectgetCustomerInvoiceAmount_Result = objContext.getCustomerInvoiceAmount(objectCustomerInvoiceViewModel.BeginDate, objectCustomerInvoiceViewModel.EndDate, objectCustomerInvoiceViewModel.CustomerId).ToList();

                if (objectCustomerInvoiceViewModel == null)
                    return null;

                return objectCustomerInvoiceViewModel;

            }
        }
        public CustomerInvoiceViewModel GetCustomerHoursAndAmount(int customerId, string type, string beginDate, string endDate, int inoviceId)
        {
            CustomerInvoiceViewModel objectCustomerInvoiceViewModel = new CustomerInvoiceViewModel();
            using (SecurityAgencyEntities objContext = new SecurityAgencyEntities())
            {
                if (string.IsNullOrEmpty(type))
                {
                    //Get beginDate and endDate first
                    CustomerInvoice objectCustomerInvoice = _repository.GetAll<CustomerInvoice>().Where(x => x.CustomerId == customerId && x.IsDeleted == false && x.InvoiceId!= inoviceId).OrderByDescending(i => i.EndDate).FirstOrDefault();
                    if (objectCustomerInvoice != null)
                    {
                        beginDate = objectCustomerInvoice.EndDate.AddDays(1).ToString();
                        endDate = objectCustomerInvoice.EndDate.AddDays(7).ToString();
                    }
                }
                //////Get values from hourlog table
                List<getCustomerInvoiceAmount_Result> objectgetCustomerInvoiceAmount_Result = objContext.getCustomerInvoiceAmount(Convert.ToDateTime(beginDate), Convert.ToDateTime(endDate), customerId).ToList();

                objectCustomerInvoiceViewModel.TotalHours = Convert.ToInt32(objectgetCustomerInvoiceAmount_Result.Sum(i=>i.TotHours));
                objectCustomerInvoiceViewModel.Amount = Convert.ToInt32(objectgetCustomerInvoiceAmount_Result.Sum(i=>i.Amount));
                objectCustomerInvoiceViewModel.BeginDate = Convert.ToDateTime(beginDate);
                objectCustomerInvoiceViewModel.EndDate = Convert.ToDateTime(endDate);
                objectCustomerInvoiceViewModel.HourlyRate = Convert.ToDecimal(objectgetCustomerInvoiceAmount_Result.FirstOrDefault().HourlyRate);
                return objectCustomerInvoiceViewModel;
            } 
        }
 public ActionResult CustomerInvoiceReport()
 {
     CustomerInvoiceViewModel objectCustomerInvoiceViewModel = new CustomerInvoiceViewModel();
     objectCustomerInvoiceViewModel.CustomerList = new SelectList(_customerComponent.GetAllCustomer(), "CustomerId", "NameEmail");
     return View(objectCustomerInvoiceViewModel);
 }