public ApproveOrderViewModel Get(Guid orderId)
        {
            MainOrder o = _orderMainRepository.GetById(orderId) as MainOrder;

            var vm = new ApproveOrderViewModel
            {
                DocumentId = o.Id.ToString(),
                DocumentReference = o.DocumentReference,
                DocumentIssuerCostCentre = o.DocumentIssuerCostCentre.Name,
                DocumentRecipientCostCentre = o.DocumentRecipientCostCentre.Name,
                DocumentIssuerUser = o.DocumentIssuerUser.Username,
                DocumentStatus = o.Status.ToString(),
                DocumentDateIssued = o.DocumentDateIssued.ToString("dd-MMM-yyyy"),
                DateRequired = o.DateRequired.ToString("dd-MMM-yyyy"),
                TotalNet = o.TotalNet,
                TotalVat = o.TotalVat,
                OrderTotal = o.TotalGross,
                //LineItems = o.LineItems.Where(n=>n.LineItemType==OrderLineItemType.PostConfirmation).Select(n => Map(n, o.Id)).ToList(),
                CanEdit = o.Status == DocumentStatus.Confirmed
            };
            if (HttpContext.Current.Session["PurchaseOrderLineItemList"] == null)
            {
                _summarizeProduct.ClearBuffer();
                List<SubOrderLineItem> list = o.PendingApprovalLineItems.ToList();
              
                foreach (SubOrderLineItem x in list)
                {
                    if (x.Product is SaleProduct || x.Product is ConsolidatedProduct)
                        _summarizeProduct.AddProduct(x.Product.Id, x.Qty, false, false, true);
                }
                List<PackagingSummary> summaryList = _summarizeProduct.GetProductSummary();
                HttpContext.Current.Session["PurchaseOrderLineItemList"] = summaryList;
            }
            else
            {
                List<PackagingSummary> summaryList = HttpContext.Current.Session["PurchaseOrderLineItemList"] as List<PackagingSummary>;

            }

            vm = GetSummaryList(vm);
            return vm;
        }
        public ApproveOrderViewModel Find(Guid orderId)
        {
            var order = _orderMainRepository.GetById(orderId);
            var vm = new ApproveOrderViewModel
                {
                    DocumentId = order.Id.ToString(),
                    DocumentReference = order.DocumentReference,
                    DocumentIssuerCostCentre = order.DocumentIssuerCostCentre.Name,
                    DocumentRecipientCostCentre = order.DocumentRecipientCostCentre.Name,
                    DocumentIssuerUser = order.DocumentIssuerUser.Username,
                    DocumentStatus = order.Status.ToString(),
                    DocumentDateIssued = order.DocumentDateIssued.ToString("dd-MMM-yyyy"),
                    DateRequired = order.DateRequired.ToString("dd-MMM-yyyy"),
                    TotalNet = order.TotalNet,
                    TotalVat = order.TotalVat,
                    OrderTotal = order.TotalGross,
                };

                foreach (var item in order.ItemSummary)
                {
                    var lineItem = new ApproveOrderViewModel.ApproveOrderLineItemViewModel()
                        {
                            Qty = item.Qty,
                            VatValue = 0,
                            ProductId = item.Product.Id,
                            ProductDesc = item.Product.Description,
                            ProductType = item.Product.GetType().ToString(),
                            LineTotal = item.TotalNet,
                            Value = item.Product.ExFactoryPrice,
                            TotalNet = item.Product.ExFactoryPrice * item.Qty,
                        };

                    vm.LineItems.Add(lineItem);
                }
            return vm;
        }
        private ApproveOrderViewModel GetSummaryList(ApproveOrderViewModel vm)
        {
            List<PackagingSummary> summaryList = _summarizeProduct.GetProductSummary();
            List<PackagingSummary> sumaryReturnable = summaryList.Where(s => s.Product is ReturnableProduct).ToList();

            sumaryReturnable = _summarizeProduct.GetMixedPackContainers(sumaryReturnable);
            foreach (PackagingSummary item in summaryList)
            {
                UpdateOrAddLineItem(vm.LineItems, item.Product, item.Quantity, item.IsEditable, item.ParentProductId, false);
            }
            foreach (PackagingSummary item in sumaryReturnable)
            {

                UpdateOrAddLineItem(vm.LineItems, item.Product, item.Quantity, false, item.ParentProductId, true);
            }
            vm.TotalNet = vm.LineItems.Sum(t => t.TotalNet);
           vm.TotalVat = vm.LineItems.Sum(t => t.TotalVat);
            vm.OrderTotal = vm.LineItems.Sum(t => t.LineTotal);

            return vm;
        }