Exemple #1
0
        public ActionResult Create(int id)
        {
            //TODO: Kolla att det inte redan finns en Faktura med detta orderID
            var order = orderRepo.GetItem(id);

            var customerGroupId = order.Customer.CustomerGroupId;

            foreach (var item in order.OrderProducts)
            {
                item.Price = GetUnitPrice(customerGroupId, (int)item.ProductId, item.AcceptedAmount) * item.AcceptedAmount;
            }

            order.OrderStatus = OrderStatus.Fakturerar;
            //orderRepo.UpdateItem(order);

            var invoice = new Invoice
            {
                Order = order,
                //OrderId = order.Id,
                InvoiceDate = DateTime.Today.Date,
                Paid        = false,
            };

            invoiceRepo.CreateItem(invoice);
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult Edit([Bind(Include = "Id,ProductId,OrderedAmount,AvailabeAmount,DeliveredAmount,AcceptedAmount,Comment,OrderId")] OrderProduct updated)
        {
            if (updated.AcceptedAmount > updated.DeliveredAmount)
            {
                ModelState.AddModelError("AcceptedAmount", "Mottaget antal är större än leveransantal.");
            }
            if (updated.AcceptedAmount < 0)
            {
                ModelState.AddModelError("AcceptedAmount", "Mottaget antal är mindre än 0.");
            }
            if (ModelState.IsValid)
            {
                orderProductRepo.UpdateItem(updated);
                var order = orderRepo.GetItem((int)updated.OrderId);
                switch (order.OrderStatus)
                {
                case OrderStatus.Behandlar:
                    return(RedirectToAction("PrepareOrder", "Orders", new { id = updated.OrderId }));

                case OrderStatus.Plockar:
                    return(View());

                case OrderStatus.Fraktar:
                    return(View());

                case OrderStatus.Levererad:
                    return(RedirectToAction("FinalizeDelivery", "Orders", new { id = updated.OrderId }));

                case OrderStatus.Fakturerar:
                    return(View());

                case OrderStatus.Arkiverad:
                    return(View());

                default:
                    return(View());
                }
            }
            ViewBag.OrderId   = new SelectList(orderRepo.GetItems(), "Id", "Id", updated.OrderId);
            ViewBag.ProductId = new SelectList(productRepo.GetItems(), "Id", "Name", updated.ProductId);
            return(View(updated));
        }
Exemple #3
0
        // GET: Orders/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // TODO: uppdatera tillgängligt antal när man klicka på details!
            var order = orderRepo.GetItem((int)id);

            if (order == null)
            {
                return(HttpNotFound());
            }
            return(View(order));
        }