Example #1
0
        public async Task <IActionResult> Search(CreateInvoiceViewModel viewModel)
        {
            int CusID = viewModel.Invoice.CustomerID;

            if (CusID > 0)
            {
                List <Reservation> reservations = await _context.Reservation
                                                  .Include(x => x.room)
                                                  .Include(x => x.period)
                                                  .Where(x => x.CustomerID == CusID).ToListAsync();

                viewModel.ReservationList = new SelectList(reservations, "ReservationID");
            }
            else
            {
                viewModel.ReservationList = new SelectList(Enumerable.Empty <SelectListItem>());
            }

            viewModel.Invoice = new Invoice();
            List <Customer> customers = await _context.Customer.ToListAsync();

            viewModel.Customers            = new SelectList(customers, "CustomerID", "Firstname", CusID);
            viewModel.SelectedCustomer     = CusID;
            viewModel.SelectedReservations = new List <int>();

            return(View("Create", viewModel));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "InvoiceId,Date,InvoiceTo,InvoiceToAddress,Reference,CareOf,CareOfEmail,CareOfNumber,InvoiceDetails,ContactId,WorkLocationId,QuoteId")] CreateInvoiceViewModel model)
        {
            if (ModelState.IsValid)
            {
                Invoice invoice = new Invoice
                {
                    InvoiceDate    = DateTime.ParseExact(model.Date, "dd-MM-yyyy", CultureInfo.InvariantCulture),
                    InvoiceId      = model.InvoiceId,
                    ContactId      = model.ContactId,
                    InvoiceDetails = model.InvoiceDetails,
                    Reference      = model.Reference,
                    Price          = model.InvoiceDetails.Sum(p => p.Price),
                    PaidDate       = null,
                    WorkLocationId = model.WorkLocationId
                };
                invoice.Add();


                // Only mark the quote finished if the invoice was successfully created
                Quote quote = Quote.GetQuote(model.QuoteId);
                quote.MarkAsFinished();
                return(Json(new { Success = true }));
            }

            return(Json(new { Success = false, errorMessage = "ModelState is invalid" }));
        }
Example #3
0
        // GET: Invoices/Create
        public async Task <IActionResult> Create()
        {
            var suppliers = await _invoicesRepository.ListSuppliersAsync();

            var subscribers = await _invoicesRepository.ListSubscribersAsync();

            var invoiceViewModel = new CreateInvoiceViewModel
            {
                Suppliers   = suppliers.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList(),
                Subscribers = subscribers.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList(),
            };

            return(View(invoiceViewModel));
        }
Example #4
0
        public async Task <ActionResult> Create()
        {
            var customers = (await _customerService.GetCustomer()).Items;
            var products  = (await _productService.GetProduct()).Items;

            var model = new CreateInvoiceViewModel
            {
                Customers         = customers,
                Products          = products,
                LoginInformations = await _sessionAppService.GetCurrentLoginInformations(),
            };

            return(View("Create", model));
        }
Example #5
0
        public IActionResult Create()
        {
            CreateInvoiceViewModel viewModel = new CreateInvoiceViewModel();

            viewModel.Invoice = new Invoice();
            List <Customer> customers = _context.Customer.ToList();

            viewModel.Customers       = new SelectList(customers, "CustomerID", "Fullname");
            viewModel.ReservationList = new SelectList(Enumerable.Empty <SelectListItem>());

            //new SelectList(_context.Reservation, "ReservationID", "Date");
            viewModel.SelectedReservations = new List <int>();

            return(View(viewModel));
        }
Example #6
0
        public ActionResult CreateInvoice(CreateInvoiceViewModel viewModel)
        {
            if (rulesEngineService.IsCustomerInvoicesEnabled() == false)
            {
                ThrowAccessDeniedException("No Access to create invoice");
            }

            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            invoiceManager.CreateInvoice(viewModel);

            return(default(PartialViewResult));
        }
Example #7
0
        /// <summary>
        /// Translates the specified view model.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <returns></returns>
        public InvoiceModel Translate(CreateInvoiceViewModel viewModel)
        {
            IPublishedContent publishedContent = settingsService.GetCustomerNode();

            CustomerModel model = new CustomerModel(publishedContent);

            return(new InvoiceModel
            {
                CustomerId = model.Id,
                CreatedTime = DateTime.Now,
                CreatedUser = userService.GetCurrentUserName(),
                LasteUpdatedTime = DateTime.Now,
                LastedUpdatedUser = userService.GetCurrentUserName(),
                InvoiceDate = viewModel.Date,
                InvoiceAmount = Convert.ToDecimal(viewModel.Amount),
                InvoiceDetails = viewModel.Details
            });
        }
Example #8
0
        public async Task <IActionResult> Create(CreateInvoiceViewModel viewModel)
        {
            viewModel.Invoice = new Invoice();

            viewModel.Invoice.Date       = DateTime.Today;
            viewModel.Invoice.EndDate    = DateTime.Today.AddDays(14);
            viewModel.Invoice.Paid       = false;
            viewModel.Invoice.CustomerID = viewModel.SelectedCustomer ?? -1;

            double Total = 0;

            if (ModelState.IsValid)
            {
                _context.Add(viewModel.Invoice);
                await _context.SaveChangesAsync();

                List <ReservationInvoice> newInvoices = new List <ReservationInvoice>();
                foreach (int reservationID in viewModel.SelectedReservations)
                {
                    Reservation reservation = _context.Reservation.Find(reservationID);
                    Total = Total + reservation.Price;
                    newInvoices.Add(new ReservationInvoice
                    {
                        ReservationID = reservationID,
                        InvoiceID     = viewModel.Invoice.InvoiceID
                    });
                }

                viewModel.Invoice.TotalPrice = Total;
                _context.Update(viewModel.Invoice);
                await _context.SaveChangesAsync();

                Invoice invoice = await _context.Invoice.Include(x => x.ReservationInvoices)
                                  .SingleOrDefaultAsync(x => x.InvoiceID == viewModel.Invoice.InvoiceID);

                invoice.ReservationInvoices.AddRange(newInvoices);
                _context.Update(invoice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //zaken terug opvullen
            return(View(viewModel));
        }
        public async Task Create_Redirects()
        {
            var invoice = new Invoice();
            // Arrange
            var mockRepo = new Mock <IInvoicesRepository>();

            mockRepo.Setup(repo => repo.AddInvoiceAsync(invoice))
            .ReturnsAsync(invoice);
            var controller = new InvoicesController(mockRepo.Object);

            // Act
            var invoiceViewModel = new CreateInvoiceViewModel();
            var result           = await controller.Create(invoiceViewModel);

            // Assert
            var redirect = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirect.ActionName);
        }
Example #10
0
        public PartialViewResult GetCreateInvoice()
        {
            LoggingService.Info(GetType());

            if (rulesEngineService.IsCustomerInvoicesEnabled())
            {
                CreateInvoiceViewModel viewModel = new CreateInvoiceViewModel();

                IPublishedContent paymentsNode = settingsService.GetPaymentsNode();

                PaymentSettingsModel settingsModel = new PaymentSettingsModel(paymentsNode);

                viewModel.ShowIncludePaymentLink = settingsModel.CustomerPaymentsEnabled;

                return(PartialView("Partials/Spectrum/Invoices/CreateInvoice", viewModel));
            }

            return(default(PartialViewResult));
        }
Example #11
0
        /// <summary>
        /// Creates the invoice.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public void CreateInvoice(CreateInvoiceViewModel viewModel)
        {
            InvoiceModel invoiceModel = invoiceTranslator.Translate(viewModel);

            int addressId = postalAddressService.GetAddressId(
                invoiceModel.CustomerId,
                "",
                "",
                "");

            int clientId = clientService.GetClientId(
                invoiceModel.CustomerId,
                addressId,
                viewModel.ClientName,
                viewModel.EmailAddress);

            invoiceModel.ClientId  = clientId;
            invoiceModel.AddressId = addressId;

            invoiceService.CreateInvoice(invoiceModel);
        }
Example #12
0
        public async Task <IActionResult> Create(CreateInvoiceViewModel invoiceViewModel)
        {
            //var invoice = invoiceViewModel.Invoice;
            //invoice.SupplierId = invoiceViewModel.SupplierId;
            //invoice.SubscriberId = invoiceViewModel.SubscriberId;

            if (ModelState.IsValid)
            {
                var invoice = new Invoice()
                {
                    DateOfIssue         = invoiceViewModel.DateOfIssue,
                    DueDate             = invoiceViewModel.DueDate,
                    InvoicePayingStatus = InvoicePayingStatus.Unpaid,
                    SubscriberId        = invoiceViewModel.SubscriberId,
                    SupplierId          = invoiceViewModel.SupplierId
                };

                await _invoicesRepository.AddInvoiceAsync(invoice);

                return(RedirectToAction(nameof(Index)));
            }

            var suppliers = await _invoicesRepository.ListSuppliersAsync();

            var subscribers = await _invoicesRepository.ListSubscribersAsync();

            //var invoiceViewModel = new InvoiceViewModel
            //{
            //    Invoice = invoice,
            //    Suppliers = suppliers.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList(),
            //    Subscribers = subscribers.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList(),
            //    SupplierId = invoice.SupplierId,
            //    SubscriberId = invoice.SubscriberId
            //};

            return(View(invoiceViewModel));
        }
Example #13
0
 private void btnCreate_Click(object sender, RoutedEventArgs e)
 {
     DataContext = new CreateInvoiceViewModel();
 }
Example #14
0
        public async Task <IActionResult> CreateInvoice(CreateInvoiceViewModel createInvoiceViewModel)
        {
            if (ModelState.IsValid)
            {
                if (signInManager.IsSignedIn(User) == true)
                {
                    SignedUserName = User.Identity.Name;
                    user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
                }

                Invoice invoice = new Invoice()
                {
                    StoreName            = createInvoiceViewModel.StoreName,
                    InvoiceProductType   = createInvoiceViewModel.InvoiceProductType,
                    InvoiceProductAmount = createInvoiceViewModel.InvoiceProductAmount,
                    InvoiceProductPrice  = createInvoiceViewModel.InvoiceProductPrice,
                    InvoiceFollowCode    = createInvoiceViewModel.InvoiceFollowCode,
                    DeliveryOffice       = createInvoiceViewModel.DeliveryOffice,
                    InvoiceDate          = createInvoiceViewModel.InvoiceDate,
                    InvoiceComments      = createInvoiceViewModel.InvoiceComments,
                    InvoiceProductWeight = null,
                    DeliveryMoney        = null,
                    InvoiceTime          = DateTime.Now.ToString("HH:mm"),
                    InvoiceStatus        = 1,
                    InvoiceCountryIndex  = createInvoiceViewModel.InvoiceCountryIndex,
                    DbPassportUserModel  = user
                };

                if (invoice.InvoiceDate == null)
                {
                    invoice.InvoiceDate = DateTime.Now;
                }

                if (dbContext.Invoices.Count() > 0)
                {
                    invoice.InvoiceNumber = dbContext.Invoices.Max(x => x.InvoiceNumber) + 1;
                }
                else
                {
                    invoice.InvoiceNumber = 1;
                }

                //======================================== If there is any image submitted then this image is added to folder
                if (createInvoiceViewModel.FormFile != null)
                {
                    var nameOfImage      = Path.GetFileNameWithoutExtension(createInvoiceViewModel.FormFile.FileName);
                    var extensionOfImage = Path.GetExtension(createInvoiceViewModel.FormFile.FileName);
                    var guid             = Guid.NewGuid();

                    var newFileName = nameOfImage + guid + extensionOfImage;


                    var rootPath = Path.Combine(_webHost.WebRootPath, "Invoice", "InvoiceGallery", newFileName);

                    using (var fileStream = new FileStream(rootPath, FileMode.Create))
                    {
                        createInvoiceViewModel.FormFile.CopyTo(fileStream);
                    }

                    invoice.FileName = newFileName;
                }


                dbContext.Invoices.Add(invoice);
                dbContext.SaveChanges();

                return(RedirectToAction("Index", "PanelPage"));
            }

            return(View());
        }