public ActionResult Create(string delivery = "", int id = 0, int receivepo = 0)
        {
            /// Authorization Check
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();

            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //find PO of given id
            Order NewOrder = OrderService.GetOrderById(id);

            if (NewOrder == null)
            {
                return(HttpNotFound());
            }

            //1 get all podetail of given po
            var podetail = NewOrder.OrderDetails.Where(x => x.WarehouseId == CurrentWarehouseId && x.IsDeleted != true);
            // 2 get all receive po detail
            //var receivepodetail = po.ReceivePOs.Select(x=>x.ReceivePODetails);
            var receivepodetail = NewOrder.OrderProcess.Where(x => x.WarehouseId == CurrentWarehouseId && x.IsDeleted != true).Select(x => x.OrderProcessID);
            //declare list of objects for view
            List <OrderProcessDetail> ReceivePOLine = new List <OrderProcessDetail>();

            foreach (var item in podetail)
            {
                //////////// // create ReceivePOLine object ///////////////////////////////
                OrderProcessDetail line = new OrderProcessDetail();
                //assigning values
                line.OrderProcessDetailID = item.OrderDetailID;
                line.ProductId            = item.ProductId;
                line.QtyProcessed         = OrderService.GetAllOrderProcessesByOrderDetailId(item.OrderDetailID, CurrentWarehouseId).Sum(x => (decimal?)x.QtyProcessed) ?? 0;
            } // end of loop

            ViewBag.rpodetail = ReceivePOLine;
            ViewBag.RPO       = receivepo;
            ViewBag.delivery  = delivery;

            return(View(NewOrder));
        }
        public ActionResult Edit(int id = 0)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var rp = OrderService.GetOrderProcessByOrderProcessId(id);

            if (rp == null)
            {
                return(HttpNotFound());
            }

            var recevivepodetail = rp.OrderProcessDetail.Where(x => x.IsDeleted != true);


            List <OrderProcessDetail> ReceivePOLine = new List <OrderProcessDetail>();

            foreach (var item in recevivepodetail)
            {
                OrderProcessDetail line = new OrderProcessDetail();
                line.OrderProcessDetailID = item.OrderProcessDetailID;
                line.ProductId            = item.ProductId;
                line.QtyProcessed         = item.QtyProcessed;

                if (line != null)
                {
                    ReceivePOLine.Add(line);
                }
            }
            ////////////PODetail lines that are not in ReceiveList. ////////////////////////////

            var detail  = OrderService.GetAllValidOrderDetailsByOrderId(rp.OrderID ?? 0);
            var rdetail = from r in rp.OrderProcessDetail where (r.IsDeleted != true) select r.OrderProcessDetailID;

            var podetail = from d in detail
                           where !(rdetail)
                           .Contains(d.OrderDetailID)
                           select d;

            List <OrderProcessDetail> PDLine = new List <OrderProcessDetail>();

            foreach (var item in podetail)
            {
                OrderProcessDetail line = new OrderProcessDetail();

                line.OrderProcessDetailID = item.OrderDetailID;
                line.ProductId            = item.ProductId;
                line.QtyProcessed         = OrderService.GetAllOrderProcessesByOrderDetailId(item.OrderDetailID, CurrentWarehouseId).Sum(x => (decimal?)x.QtyProcessed) ?? 0;
            }

            ViewBag.rpodetail = ReceivePOLine;
            ViewBag.pdetail   = PDLine;

            return(View(rp));
        }