Beispiel #1
0
        public void SaveReceiveOrder(ReceivedOrder receiveOrder)
        {
            if (receiveOrder.ReceivedDate != null && receiveOrder.ReceivedQuantity != null)
            {
                String orderId = receiveOrder.OrderId.ToString();
                // orderNoList.Add(orderId);
                // bool checkDuplicate = CheckOrderNo(orderId);
                Order ord = context.Orders.Where(x => x.OrderId == receiveOrder.OrderId).FirstOrDefault();
                ord.ReceivedDate = receiveOrder.ReceivedDate;
                ord.OrderStatus  = "Completed";
                context.SaveChanges();

                OrderDetail orde = context.OrderDetails.Where(x => x.OrderId == receiveOrder.OrderId && x.ItemId.Equals(receiveOrder.ItemId)).FirstOrDefault();
                orde.Received_Quantity = receiveOrder.ReceivedQuantity;
                context.SaveChanges();


                StockCard stoCard = context.StockCards.OrderByDescending(x => x.Update_Date).Where(x => x.ItemId.Equals(receiveOrder.ItemId)).FirstOrDefault();


                StockCard scd = new StockCard();
                scd.ItemId      = receiveOrder.ItemId;
                scd.Update_Date = (DateTime)receiveOrder.ReceivedDate;

                Supplier supp = context.Suppliers.Where(x => x.SupplierId == ord.SupplierId).FirstOrDefault();
                scd.Description = supp.SupplierName;
                scd.Quantity    = receiveOrder.ReceivedQuantity;

                if (stoCard != null)
                {
                    if (stoCard.Update_Date.Date.Equals(scd.Update_Date.Date))
                    {
                        if (stoCard.Update_Date.Hour.Equals(scd.Update_Date.Hour))
                        {
                            stoCard.Balance  = receiveOrder.ReceivedQuantity;
                            stoCard.Quantity = receiveOrder.ReceivedQuantity;
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        scd.Balance = stoCard.Balance + receiveOrder.ReceivedQuantity;
                        context.StockCards.Add(scd);
                        context.SaveChanges();
                    }
                }

                else if (stoCard == null)
                {
                    scd.Balance = receiveOrder.ReceivedQuantity;
                    context.StockCards.Add(scd);
                    context.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public JsonResult Order(string CustomerID, [FromBody] ReceivedOrder order)   // [FromBody] string order
        {
            IEnumerable <Order>   myOrders = db.GetCustomerOrders(CustomerID);
            IEnumerable <Product> products = db.GetAllProducts();
            Order toPost = null;

            if (myOrders.Any(item => item.OrderID == order.RepeatOrder))
            {
                //repeat order
                toPost             = (Order)(myOrders.Where(item => item.OrderID == order.RepeatOrder).First());
                toPost.OrderID     = 0;
                toPost.ShippedDate = DateTime.Parse("0001-01-01T00:00:00");

                if (toPost.Details.Any(detail => products.Where(prod => prod.ProductID == detail.ProductID).First().Discontinued))
                {
                    return(new JsonResult(new { Status = "Discontinued Products in order, unable to repeat" }));
                }

                db.SaveOrder(toPost);

                foreach (OrderDetail orderDetail in toPost.Details)
                {
                    orderDetail.OrderID = toPost.OrderID;
                    db.SaveDetail(orderDetail);
                }
            }
            else
            {
                //new order
                toPost              = new Order();
                toPost.CustomerID   = CustomerID;
                toPost.ShippedDate  = DateTime.Parse("0001-01-01T00:00:00");
                toPost.OrderID      = 0;
                toPost.OrderDate    = DateTime.Now;
                toPost.RequiredDate = DateTime.Now.AddDays(28);
                db.SaveOrder(toPost);
                foreach (OrderDetail orderDetail in order.Products)
                {
                    orderDetail.OrderID   = toPost.OrderID;
                    orderDetail.UnitPrice = products.Where(prod => prod.ProductID == orderDetail.ProductID).First().UnitPrice;
                    if (orderDetail.Quantity > 5)
                    {
                        orderDetail.Discount = 0.05m;
                    }
                    else
                    {
                        orderDetail.Discount = 0;
                    }
                    db.SaveDetail(orderDetail);
                }
            }
            return(new JsonResult(db.GetCustomerOrders(CustomerID).Where(item => item.OrderID == toPost.OrderID).First()));
        }
Beispiel #3
0
        public List <ReceivedOrder> GetOrderList(long orderId)
        {
            List <ReceivedOrder> recOrderList = new List <ReceivedOrder>();
            var orderList = from ode in context.OrderDetails
                            where
                            //ode.Order.OrderStatus == "Approve" || ode.Order.OrderStatus == "Completed"
                            ode.Order.OrderId == orderId
                            select new
            {
                ode.OrderId,
                ode.ItemId,
                ode.Item.ItemName,
                OrderDate    = (DateTime?)ode.Order.OrderDate,
                ReceivedDate = (DateTime?)ode.Order.ReceivedDate,
                ode.Order_Quantity,
                ode.Received_Quantity,
                ode.Price
            };


            foreach (var p in orderList)
            {
                ReceivedOrder order = new ReceivedOrder();
                order.OrderId          = p.OrderId;
                order.ItemId           = p.ItemId;
                order.ItemName         = p.ItemName;
                order.OrderDate        = p.OrderDate;
                order.ReceivedDate     = p.ReceivedDate;
                order.OrderQuantity    = p.Order_Quantity;
                order.ReceivedQuantity = p.Received_Quantity;
                order.Price            = p.Price;
                recOrderList.Add(order);
            }

            return(recOrderList);
        }
Beispiel #4
0
 public void SaveReceiveOrder(ReceivedOrder receiveOrder)
 {
     receiveDAOImpl.SaveReceiveOrder(receiveOrder);
 }