public ActionResult _FilterPostDispatch(SaleInvoiceFilterViewModel vm) { List <DirectSaleInvoiceLineViewModel> temp = _SaleInvoiceLineService.GetSaleDispatchForFilters(vm); DirectSaleInvoiceListViewModel svm = new DirectSaleInvoiceListViewModel(); svm.DirectSaleInvoiceLineViewModel = temp; return(PartialView("_Results", svm)); }
public ActionResult _ResultsPost(DirectSaleInvoiceListViewModel vm) { int Cnt = 0; SaleInvoiceHeader Sh = new SaleInvoiceHeaderService(_unitOfWork).FindDirectSaleInvoice(vm.DirectSaleInvoiceLineViewModel.FirstOrDefault().SaleInvoiceHeaderId); List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; bool HeaderChargeEdit = false; //SaleInvoiceHeader Header = new SaleInvoiceHeaderService(_unitOfWork).Find(vm.DirectSaleInvoiceLineViewModel.FirstOrDefault().SaleInvoiceHeaderId); SaleInvoiceSetting Settings = new SaleInvoiceSettingService(_unitOfWork).GetSaleInvoiceSettingForDocument(Sh.DocTypeId, Sh.DivisionId, Sh.SiteId); int?MaxLineId = new SaleInvoiceLineChargeService(_unitOfWork).GetMaxProductCharge(Sh.SaleInvoiceHeaderId, "Web.SaleInvoiceLines", "SaleInvoiceHeaderId", "SaleInvoiceLineId"); int PersonCount = 0; int CalculationId = Settings.CalculationId; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); if (ModelState.IsValid) { foreach (var item in vm.DirectSaleInvoiceLineViewModel) { decimal balqty = (from p in db.ViewSaleDispatchBalance where p.SaleDispatchLineId == item.SaleDispatchLineId select p.BalanceQty).FirstOrDefault(); if (item.Qty > 0 && item.Qty <= balqty) { SaleInvoiceLine line = new SaleInvoiceLine(); line.SaleInvoiceHeaderId = item.SaleInvoiceHeaderId; line.SaleDispatchLineId = item.SaleDispatchLineId; line.UnitConversionMultiplier = item.UnitConversionMultiplier; line.Rate = item.Rate; line.DealUnitId = item.DealUnitId; line.DealQty = item.Qty * item.UnitConversionMultiplier ?? 0; line.DiscountPer = item.DiscountPer; if (Settings.CalculateDiscountOnRate) { var temprate = item.Rate - (item.Rate * item.DiscountPer / 100); line.Amount = line.DealQty * temprate ?? 0; } else { var DiscountAmt = (item.Rate * line.DealQty) * item.DiscountPer / 100; line.Amount = (item.Rate * line.DealQty) - (DiscountAmt ?? 0); } line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.SaleInvoiceLineId = pk; line.Dimension1Id = item.Dimension1Id; line.Dimension2Id = item.Dimension2Id; line.SaleOrderLineId = item.SaleOrderLineId; line.DiscountPer = item.DiscountPer; line.ProductId = item.ProductId; line.Qty = item.Qty; line.Remark = item.Remark; line.SaleDispatchLineId = item.SaleDispatchLineId; line.ObjectState = Model.ObjectState.Added; _SaleInvoiceLineService.Create(line); SaleInvoiceLineDetail linedetail = new SaleInvoiceLineDetail(); linedetail.SaleInvoiceLineId = line.SaleInvoiceLineId; linedetail.RewardPoints = item.RewardPoints; _SaleInvoiceLineDetailService.Create(linedetail); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.SaleInvoiceLineId, HeaderTableId = item.SaleInvoiceHeaderId, PersonID = Sh.BillToBuyerId }); pk++; Cnt = Cnt + 1; } } new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, vm.DirectSaleInvoiceLineViewModel.FirstOrDefault().SaleInvoiceHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.SaleInvoiceHeaderCharges", "Web.SaleInvoiceLineCharges", out PersonCount, Sh.DocTypeId, Sh.SiteId, Sh.DivisionId); //Saving Charges foreach (var item in LineCharges) { SaleInvoiceLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, SaleInvoiceLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; new SaleInvoiceLineChargeService(_unitOfWork).Create(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { SaleInvoiceHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, SaleInvoiceHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = vm.DirectSaleInvoiceLineViewModel.FirstOrDefault().SaleInvoiceHeaderId; POHeaderCharge.PersonID = Sh.BillToBuyerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; new SaleInvoiceHeaderChargeService(_unitOfWork).Create(POHeaderCharge); } else { var footercharge = new SaleInvoiceHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; new SaleInvoiceHeaderChargeService(_unitOfWork).Update(footercharge); } } 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 = Sh.DocTypeId, DocId = Sh.SaleInvoiceHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Sh.DocNo, DocDate = Sh.DocDate, DocStatus = Sh.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }