Beispiel #1
0
        public ActionResult Invoice(int OrderNumber, int InvoiceID)
        {
            #region Prep Utilities

            myHandler = new BusinessLogicHandler();
            InvoiceModel model = new InvoiceModel();

            #endregion

            #region Get Invoice Data
            model.myInvoice = new Invoice();
            model.myInvoice = myHandler.GetInvoice(InvoiceID);
            #endregion

            #region Get Invoice Lines
            model.InvoiceLine = new List<InvoiceItem>();
            model.InvoiceLine = myHandler.GetInvoiceItems(InvoiceID);
            if(model.InvoiceLine != null)
            {
                model.totally = 0;
                foreach(var item in model.InvoiceLine)
                { model.totally += item.Price; }
            }
            #endregion

            #region Get Order

            model.Orders = new List<Order>();
            model.Orders = myHandler.GetAllOrdersForInvoice(InvoiceID);

            #endregion

            #region Get Order Lines

            model.OrderLine = new List<OrderItem>();

            foreach (var item in model.Orders)
            {
                model.OrderLine.AddRange(myHandler.GetOrderItemsList(item.OrderNo));
            }

            #endregion

            #region View Supplier Involved

            model.Suppliers = new List<urbanbooks.Supplier>();

            foreach (var item in model.Orders)
            {
                model.Suppliers.Add(myHandler.GetSupplier(item.SupplierID));
            }

            #endregion

            return View(model);
        }
Beispiel #2
0
        public async Task<ActionResult> Receipt(int? IID)
        {
            List<CartItem> myItems = new List<CartItem>();
            myItems = (List<CartItem>)Session["myItems"];
            ProductViewModel model = new ProductViewModel();
            myHandler = new BusinessLogicHandler();
            model = (ProductViewModel)Session["deliverData"];

            #region Get Cart Items

            List<Book> ifBooks = new List<Book>();
            List<Technology> ifGadget = new List<Technology>();

            foreach (var item in myItems)
            {
                if (myHandler.CheckProductType(item.ProductID))
                {
                    Book book = new Book();
                    book = myHandler.GetBook(item.ProductID);
                    ifBooks.Add(book);
                }
                else
                {
                    Technology gadget = new Technology();
                    gadget = myHandler.GetTechnologyDetails(item.ProductID);
                    ifGadget.Add(gadget);
                }

                //try
                //{
                //    Book book = new Book();
                //    book = myHandler.GetBook(item.ProductID);
                //    ifBooks.Add(book);
                //}
                //catch
                //{
                //    Technology gadget = new Technology();
                //    gadget = myHandler.GetTechnologyDetails(item.ProductID);
                //    ifGadget.Add(gadget);
                //}
            }

            model.allTechnology = ifGadget;
            model.allBook = ifBooks;
            model.allCartItem = myItems;

            #endregion

            #region Push User Details

            string userName = User.Identity.GetUserName();
            ApplicationDbContext dataSocket = new ApplicationDbContext();
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
            userMgr = new ApplicationUserManager(myStore);
            var user = userMgr.FindByEmail(userName);

            model.UserDetails = new ProvideUser();
            model.UserDetails.Address = user.Address;
            model.UserDetails.email = user.Email;
            model.UserDetails.PhoneNumber = user.PhoneNumber;
            CustomerContext customer = new CustomerContext();
            Customer thisCust = new Customer();
            thisCust = customer.Customers.FirstOrDefault(cust => cust.User_Id == user.Id);
            model.UserDetails.LName = thisCust.LastName;
            model.UserDetails.Name = thisCust.FirstName;
            #endregion

            #region Push Invoice nfo
            model.recieptData = new Invoice();
            model.recieptData = myHandler.GetInvoice(IID.GetValueOrDefault());

            #endregion

            #region Push Company nfo

            myHandler = new BusinessLogicHandler();
            model.company = new Company();
            model.company = myHandler.GetCompanyDetail();

            #endregion

            #region Push Delivery nfo

            Delivery shipping = new Delivery();
            myHandler = new BusinessLogicHandler();
            shipping = myHandler.GetDeliveryDetails(model.recieptData.DeliveryServiceID);
            model.deliveryHelper.DeliveryServiceName = shipping.ServiceName;
            model.deliveryHelper.DeliveryServicePrice = shipping.Price;
            model.deliveryHelper.DeliveryServiceType = shipping.ServiceType;

            #endregion

            #region Calculate

            List<ProductViewModel.CartHelper> itemList = new List<ProductViewModel.CartHelper>();
            ProductViewModel.CartHelper cartHelp;
            if (myItems != null)
            {
                if (ifBooks != null)
                {
                    var revised = from rev in ifBooks
                                  join item in myItems on rev.ProductID equals item.ProductID
                                  where rev.ProductID == item.ProductID
                                  select new { rev.ProductID, rev.SellingPrice, item.Quantity, item.CartItemID };
                    foreach (var ite in revised)
                    {
                        cartHelp = new ProductViewModel.CartHelper();
                        cartHelp.ProductID = ite.ProductID;
                        cartHelp.CartItemID = ite.CartItemID;
                        cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                        itemList.Add(cartHelp);
                    }
                }
            }
            if (myItems != null)
            {
                if (ifGadget != null)
                {
                    var revised = from rev in ifGadget
                                  join item in myItems on rev.ProductID equals item.ProductID
                                  where rev.ProductID == item.ProductID
                                  select new { rev.ProductID, rev.SellingPrice, item.Quantity, item.CartItemID };
                    foreach (var ite in revised)
                    {
                        cartHelp = new ProductViewModel.CartHelper();
                        cartHelp.ProductID = ite.ProductID;
                        cartHelp.CartItemID = ite.CartItemID;
                        cartHelp.TotalPerItem = (ite.SellingPrice * ite.Quantity);
                        itemList.Add(cartHelp);
                    }
                }
            }

            double cartTotal = Convert.ToDouble(Session["cartTotal"].ToString());
            cartTotal = cartTotal / 100;
            myHandler = new BusinessLogicHandler();
            List<Company> company = myHandler.GetCompanyDetails();
            double vat = 0;
            cartTotal += Convert.ToDouble(model.deliveryHelper.DeliveryServicePrice);
            foreach (var item in company)
            { vat = item.VATPercentage; }
            vat = vat + 1;
            double subTotal = cartTotal / vat;
            double vatAmount = cartTotal - subTotal;
            ProductViewModel.CartConclude finishing = new ProductViewModel.CartConclude();
            finishing.CartTotal = cartTotal;
            finishing.VatAddedTotal = vatAmount;
            finishing.SubTotal = subTotal;
            model.ItsA_wrap = new List<ProductViewModel.CartConclude>();
            model.ItsA_wrap.Add(finishing);

            model.secureCart = itemList;
            #endregion

            #region Clear the cart
            foreach (var item in itemList)
            {
                myHandler = new BusinessLogicHandler();
                myHandler.DeleteCartItem(item.CartItemID);
            }

            #endregion

            #region Clear SESSION
            Session["myItems"] = null;
            Session["cartTotal"] = (double) await GetCartTotal(user.Carts.CartID);
            #endregion

            #region Prep for exporting to PDF
            Session["pdf"] = model;
            #endregion

            return View(model);
        }
Beispiel #3
0
        public ActionResult Yearly(RangeViewModel model, FormCollection collector)
        {
            #region Prep Utilities
            model.Month = new Models.Monthly();
            BusinessLogicHandler myHandler = new BusinessLogicHandler();
            model.MonthlySales = new List<Monthly>();
            string date = collector.GetValue("Range.From").AttemptedValue;
            model.Month.From = date;
            string dateFrom = 01 + "/" + 01 + "/" + date;
            DateTime from = Convert.ToDateTime(dateFrom);
            date = collector.GetValue("Range.To").AttemptedValue;
            model.Month.To = date;
            dateFrom = 01 + "/" + 01 + "/" + date;
            DateTime to = Convert.ToDateTime(dateFrom);

            #endregion

            try
            {

                #region Get init Data
                IEnumerable<InvoiceItem> rawInvoiceData = myHandler.SalesGroupedByInvoiceID(from, to);
                rawInvoiceData.OrderBy(m => m.InvoiceID);
                #endregion

                #region All

                if (model.radioButtons == "All" || model.radioButtons == null)
                {
                    foreach (var item in rawInvoiceData)
                    {
                        Monthly customJob = new Monthly();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.Month = xdate;
                        customJob.TotalSales = item.Price;
                        model.MonthlySales.Add(customJob);
                    }
                }
                #endregion

                #region Books

                else if (model.radioButtons == "Book")
                {
                    foreach (var item in rawInvoiceData)
                    {

                        Monthly customJob = new Monthly();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.Month = xdate;
                        IEnumerable<InvoiceItem> rawItems = myHandler.GetInvoiceItems(item.InvoiceID);
                        foreach (var inv in rawItems)
                        {
                            if (myHandler.CheckProductType(inv.ProductID))
                            {
                                if (customJob.TotalSales == 0.0)
                                { customJob.TotalSales = inv.Price * inv.Quantity; }
                                else { customJob.TotalSales += inv.Price * inv.Quantity; }
                            }
                        }
                        if (customJob.TotalSales == 0.0)
                        { }
                        else
                        { model.MonthlySales.Add(customJob); }

                    }
                }
                #endregion

                #region Devices
                else if (model.radioButtons == "Dev")
                {
                    foreach (var item in rawInvoiceData)
                    {
                        Monthly customJob = new Monthly();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.Month = xdate;
                        IEnumerable<InvoiceItem> rawItems = myHandler.GetInvoiceItems(item.InvoiceID);
                        foreach (var inv in rawItems)
                        {
                            if (myHandler.CheckProductType(inv.ProductID))
                            {

                            }
                            else
                            {
                                if (customJob.TotalSales == 0.0)
                                { customJob.TotalSales = inv.Price * inv.Quantity; }
                                else { customJob.TotalSales += inv.Price * inv.Quantity; }
                            }
                        }
                        if (customJob.TotalSales == 0.0)
                        { }
                        else
                        { model.MonthlySales.Add(customJob); }
                    }
                }
                #endregion

                #region Clean Up My List

                IEnumerable<Monthly> rawList = model.MonthlySales.Distinct();
                rawList.OrderBy(m => m.Month);
                List<string> Date = new List<string>();
                List<double> metaPrice = new List<double>();
                model.MonthlySales = new List<Monthly>();
                foreach (var item in rawList)
                {
                    if (Date.Contains(item.Month))
                    {
                        int y = Date.IndexOf(item.Month);
                        metaPrice[y] += item.TotalSales;
                    }
                    else
                    {
                        Date.Add(item.Month);
                        metaPrice.Add(item.TotalSales);
                    }
                }
                int zed = 0;
                foreach (var item in Date)
                {
                    Monthly month = new Monthly();
                    month.Month = item;
                    month.TotalSales = metaPrice[zed];
                    model.MonthlySales.Add(month);
                    zed++;
                }
                #endregion

                #region Calc Total

                model.Total = new TotalClass();
                foreach (var item in model.MonthlySales)
                {
                    model.Total.Total += item.TotalSales;
                }

                #endregion
            }
            catch
            {
                model.Total = new TotalClass();
            }

            return View(model);
        }
        public ActionResult Search(FormCollection collector)
        {
            #region Prep Utilities

            string Query = collector.GetValue("query").AttemptedValue;
            myHandler = new BusinessLogicHandler();
            Supplier supplier = new Supplier();
            InvoiceModel model = new InvoiceModel();

            #endregion

            #region Get User(Supplier)

            string userName = User.Identity.GetUserName();
            ApplicationDbContext dataSocket = new ApplicationDbContext();
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
            _userManager = new ApplicationUserManager(myStore);
            var user = _userManager.FindByEmail(userName);

            #endregion

            #region Get Supplier Details

            supplier = myHandler.GetSupplier(user.Id);

            #endregion


            #region Get the data

            model.Order = new Order();
            model.Invoice = new Invoice();
            try
            {
                model.Order = myHandler.GetOrder(Convert.ToInt32(Query));
            }
            catch
            { model.Order = null; }
            try
            {
                model.Invoice = myHandler.GetInvoice(Convert.ToInt32(Query));
            }
            catch
            { model.Invoice = null; }
            ///get product
            #endregion


            return View(model);
        }
Beispiel #5
0
        public ActionResult Detailed(RangeViewModel model, FormCollection collector)
        {
            #region Prep Utilities

            BusinessLogicHandler myHandler = new BusinessLogicHandler();
            IEnumerable<InvoiceItem> invoiceItems;
            model.Detailed = new List<DetailedCustom>();
            string[] date = collector.GetValue("myRange.From").AttemptedValue.Split('/');
            string dateFrom = date[1] + "/" + date[0] + "/" + date[2];
            DateTime from = Convert.ToDateTime(dateFrom);
            date = collector.GetValue("myRange.To").AttemptedValue.Split('/');
            dateFrom = date[1] + "/" + date[0] + "/" + date[2];
            model.myRange.To = Convert.ToDateTime(dateFrom);
            DateTime to = Convert.ToDateTime(dateFrom);

            #endregion

            try
            {

                #region Get The Data

                invoiceItems = myHandler.SalesGroupedByInvoiceID(from, to);
                invoiceItems.OrderBy(m => m.InvoiceID);

                #endregion

                #region All

                if (model.radioButtons == "All" || model.radioButtons == null)
                {
                    int inv = 0;
                    foreach (var item in invoiceItems)
                    {
                        inv = item.InvoiceID;
                        DetailedCustom customJob = new DetailedCustom();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("dddd dd MMMM yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.DateIssued = xdate;
                        customJob.InvoiceID = item.InvoiceID;
                        customJob.InvoiceTotal = item.Price;
                        model.Detailed.Add(customJob);
                    }
                }
                #endregion

                #region Books

                else if (model.radioButtons == "Book")
                {
                    foreach (var item in invoiceItems)
                    {

                        DetailedCustom customJob = new DetailedCustom();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("dddd dd MMMM yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.DateIssued = xdate;
                        customJob.InvoiceID = item.InvoiceID;
                        IEnumerable<InvoiceItem> rawItems = myHandler.GetInvoiceItems(item.InvoiceID);
                        foreach (var inv in rawItems)
                        {
                            if (myHandler.CheckProductType(inv.ProductID))
                            {
                                if (customJob.InvoiceTotal == 0.0)
                                { customJob.InvoiceTotal = inv.Price * inv.Quantity; }
                                else { customJob.InvoiceTotal += inv.Price * inv.Quantity; }
                            }
                        }
                        if (customJob.InvoiceTotal == 0.0)
                        { }
                        else
                        { model.Detailed.Add(customJob); }

                    }
                }
                #endregion

                #region Devices
                else if (model.radioButtons == "Dev")
                {
                    foreach (var item in invoiceItems)
                    {
                        DetailedCustom customJob = new DetailedCustom();
                        Invoice invoice = new Invoice();
                        invoice = myHandler.GetInvoice(item.InvoiceID);
                        string xdate = invoice.DateCreated.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                        customJob.DateIssued = xdate;
                        customJob.InvoiceID = item.InvoiceID;
                        IEnumerable<InvoiceItem> rawItems = myHandler.GetInvoiceItems(item.InvoiceID);
                        foreach (var inv in rawItems)
                        {
                            if (myHandler.CheckProductType(inv.ProductID))
                            {

                            }
                            else
                            {
                                if (customJob.InvoiceTotal == 0.0)
                                { customJob.InvoiceTotal = inv.Price * inv.Quantity; }
                                else { customJob.InvoiceTotal += inv.Price * inv.Quantity; }
                            }
                        }
                        if (customJob.InvoiceTotal == 0.0)
                        { }
                        else
                        { model.Detailed.Add(customJob); }
                    }
                }
                #endregion

                #region Clean Up List

                model.Detailed.OrderBy(m => m.InvoiceID);
                List<DetailedCustom> cleanList = new System.Collections.Generic.List<DetailedCustom>();
                cleanList = model.Detailed.Distinct().ToList();
                model.Detailed = new List<DetailedCustom>();
                model.Detailed = cleanList;

                #endregion

                #region Calc Total

                model.Total = new TotalClass();
                foreach (var item in model.Detailed)
                {
                    model.Total.Total += item.InvoiceTotal;
                }

                #endregion
            }
            catch
            { model.Total = new TotalClass(); }

            return View(model);
        }