private void SaveReturnItems(ReturnSaleDetailExtn item, int?billNo) { _rmsEntities.ReturnDamagedStocks.Add(new ReturnDamagedStock() { isReturn = true, PriceId = item.PriceId, ProductId = item.ProductId, Quantity = item.ReturnQty, BillId = billNo }); var stock = _rmsEntities.Stocks.Where(s => s.PriceId == item.PriceId && s.ProductId == item.ProductId).FirstOrDefault(); stock.Quantity += item.ReturnQty; }
private void OnGetBill(object parameter) { PanelLoading = true; var GetBillTask = System.Threading.Tasks.Task.Run(() => { _returnSalesDetailsList = new ObservableCollection <ReturnSaleDetailExtn>(); var customerBill = RMSEntitiesHelper.CheckIfBillExists(BillNo.Value, _categoryId); if (customerBill == null) { PanelLoading = false; return; } _billSales = _rmsEntities.Sales.Where(s => s.RunningBillNo == BillNo && customerBill.CustomerId == s.CustomerId).FirstOrDefault(); CustomerName = _billSales.Customer.Name; SaleDate = _billSales.AddedOn.Value; PaymentMode pm = new PaymentMode(); ModeOfPayment = pm.GetPaymentString(_billSales.PaymentMode); var saleDetailsForBill = _rmsEntities.SaleDetails.Where(b => b.BillId == _billSales.BillId); foreach (var saleDetailItem in saleDetailsForBill.ToList()) { //Get the item and check if there is any return done for the item. var returnQty = _rmsEntities.ReturnDamagedStocks.FirstOrDefault(b => b.BillId == _billSales.BillId && saleDetailItem.ProductId == b.ProductId); var remainingQty = 0.0M; if (returnQty != null) { remainingQty = saleDetailItem.Qty.Value - returnQty.Quantity; if (remainingQty == 0) { continue; } } else { remainingQty = saleDetailItem.Qty.Value; } var productPrice = _rmsEntities.PriceDetails.Where(p => p.PriceId == saleDetailItem.PriceId).FirstOrDefault(); var saleDetailExtn = new ReturnSaleDetailExtn() { Discount = saleDetailItem.Discount, PriceId = saleDetailItem.PriceId, ProductId = saleDetailItem.ProductId, Qty = remainingQty, OriginalQty = saleDetailItem.Qty, SellingPrice = saleDetailItem.SellingPrice, BillId = saleDetailItem.BillId, CostPrice = productPrice.Price, ProductName = _rmsEntities.Products.FirstOrDefault(p => p.Id == saleDetailItem.ProductId).Name, //AvailableStock = productPrice.Quantity, Amount = productPrice.SellingPrice * saleDetailItem.Qty }; ReturnSaleDetailList.Add(saleDetailExtn); saleDetailExtn.PropertyChanged += (s, e) => { if (e.PropertyName == Constants.RETURN_QTY) { saleDetailExtn.ReturnAmount = saleDetailExtn.SellingPrice.Value * saleDetailExtn.ReturnQty; TotalAmount = _returnSalesDetailsList.Sum(p => p.ReturnAmount); } }; //tempTotalAmount += productPrice.SellingPrice * remainingQty; } //TotalAmount = tempTotalAmount; System.Threading.Thread.Sleep(1000); }).ContinueWith( (t) => { PanelLoading = false; RaisePropertyChanged("ReturnSaleDetailList"); IsBillBasedReturn = true; }); }