public ActionResult _FilterPostOrders(SaleDeliveryFilterViewModel vm)
        {
            List <SaleDeliveryLineViewModel> temp = _SaleDeliveryLineService.GetSaleInvoicesForFilters(vm).ToList();
            SaleDeliveryListViewModel        svm  = new SaleDeliveryListViewModel();

            svm.SaleDeliveryLineViewModel = temp;
            return(PartialView("_Results", svm));
        }
        public ActionResult _ResultsPost(SaleDeliveryListViewModel vm)
        {
            int Cnt = 0;


            SaleDeliveryHeader Dh = new SaleDeliveryHeaderService(_unitOfWork).Find(vm.SaleDeliveryLineViewModel.FirstOrDefault().SaleDeliveryHeaderId);

            SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(Dh.DocTypeId, Dh.DivisionId, Dh.SiteId);



            int pk = 0;
            int PackingPrimaryKey  = 0;
            int DeliveryPrimaryKey = 0;


            List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>();

            if (ModelState.IsValid)
            {
                foreach (var item in vm.SaleDeliveryLineViewModel)
                {
                    decimal balqty = (from p in db.ViewSaleInvoiceBalanceForDelivery
                                      where p.SaleInvoiceLineId == item.SaleInvoiceLineId
                                      select p.BalanceQty).FirstOrDefault();
                    if (item.Qty > 0 && item.Qty <= balqty)
                    {
                        SaleDeliveryLine Dl = new SaleDeliveryLine();

                        Dl.UnitConversionMultiplier = item.UnitConversionMultiplier ?? 0;
                        Dl.DealQty              = item.Qty * item.UnitConversionMultiplier ?? 0;
                        Dl.DealUnitId           = item.DealUnitId;
                        Dl.CreatedBy            = User.Identity.Name;
                        Dl.CreatedDate          = DateTime.Now;
                        Dl.ModifiedBy           = User.Identity.Name;
                        Dl.ModifiedDate         = DateTime.Now;
                        Dl.SaleDeliveryHeaderId = Dh.SaleDeliveryHeaderId;
                        Dl.Qty                = item.Qty;
                        Dl.Remark             = item.Remark;
                        Dl.SaleInvoiceLineId  = item.SaleInvoiceLineId;
                        Dl.SaleDeliveryLineId = DeliveryPrimaryKey++;
                        Dl.ObjectState        = Model.ObjectState.Added;
                        _SaleDeliveryLineService.Create(Dl);



                        LineList.Add(new LineDetailListViewModel {
                            Amount = 0, Rate = 0, LineTableId = Dl.SaleDeliveryLineId, HeaderTableId = item.SaleDeliveryHeaderId, PersonID = Dh.SaleToBuyerId
                        });

                        pk++;
                        Cnt = Cnt + 1;
                    }
                }

                new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    return(PartialView("_Results", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = Dh.DocTypeId,
                    DocId        = Dh.SaleDeliveryHeaderId,
                    ActivityType = (int)ActivityTypeContants.MultipleCreate,
                    DocNo        = Dh.DocNo,
                    DocDate      = Dh.DocDate,
                    DocStatus    = Dh.Status,
                }));


                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }