public ActionResult DuePaymentSearchResult(DuePaymentViewModel DuePaymentViewModel) { if (DuePaymentViewModel.TransAmount > 0) { PaymentTransaction PaymentTransaction = new PaymentTransaction(); PaymentTransaction.Id = Guid.NewGuid(); PaymentTransaction.OrderNumber = DuePaymentViewModel.BillTransaction.OrderNumber; PaymentTransaction.Patient_Id = DuePaymentViewModel.Patient.Id; PaymentTransaction.Doctor_Id = DuePaymentViewModel.Doctor.Id; PaymentTransaction.Branch_Id = DuePaymentViewModel.BillTransaction.Branch_Id; PaymentTransaction.PaymentDate = DateTime.Now; PaymentTransaction.Transtype = "Payment"; PaymentTransaction.TransAmount = DuePaymentViewModel.TransAmount; db.PaymentTransactions.Add(PaymentTransaction); db.SaveChanges(); } var OrderNumber = DuePaymentViewModel.BillTransaction.OrderNumber; var billTransaction = db.BillTransactions.SingleOrDefault(x => x.OrderNumber == OrderNumber && x.Transtype == "Bill"); var patient = db.Patients.SingleOrDefault(x => x.Id == billTransaction.Patient_Id); DuePaymentViewModel.BillTransaction = billTransaction; DuePaymentViewModel.Patient = patient; DuePaymentViewModel.PaymentTransactions = db.PaymentTransactions.Where(x => x.OrderNumber == OrderNumber).ToList(); DuePaymentViewModel.PaymentTransactionSum = DuePaymentViewModel.PaymentTransactions.Sum(x => x.TransAmount); DuePaymentViewModel.TotalDue = DuePaymentViewModel.BillTransaction.BillAmount - DuePaymentViewModel.PaymentTransactionSum; DuePaymentViewModel.Doctor = db.Doctors.SingleOrDefault(x => x.Id == billTransaction.Doctor_Id); DuePaymentViewModel.InvoiceCheckout = db.InvoiceCheckouts.SingleOrDefault(x => x.OrderNumber == OrderNumber); return(View(DuePaymentViewModel)); }
public ActionResult DuePaymentSearchResult(long OrderNumber) { DuePaymentViewModel DuePaymentViewModel = new DuePaymentViewModel(); var billTransactionCounter = db.BillTransactions.Where(x => x.OrderNumber == OrderNumber && x.Transtype == "Bill").Count(); if (billTransactionCounter == 1) { var billTransaction = db.BillTransactions.SingleOrDefault(x => x.OrderNumber == OrderNumber && x.Transtype == "Bill"); var patient = db.Patients.SingleOrDefault(x => x.Id == billTransaction.Patient_Id); DuePaymentViewModel.BillTransaction = billTransaction; DuePaymentViewModel.Patient = patient; DuePaymentViewModel.PaymentTransactions = db.PaymentTransactions.Where(x => x.OrderNumber == OrderNumber).ToList(); DuePaymentViewModel.PaymentTransactionSum = DuePaymentViewModel.PaymentTransactions.Sum(x => x.TransAmount); DuePaymentViewModel.TotalDue = DuePaymentViewModel.BillTransaction.BillAmount - DuePaymentViewModel.PaymentTransactionSum; DuePaymentViewModel.Doctor = db.Doctors.SingleOrDefault(x => x.Id == billTransaction.Doctor_Id); DuePaymentViewModel.InvoiceCheckout = db.InvoiceCheckouts.SingleOrDefault(x => x.OrderNumber == OrderNumber); } else if (billTransactionCounter == 0) { return(RedirectToAction("DuePayment", new { Message = "No data found with this order number." })); } else { return(RedirectToAction("DuePayment", new { Message = "Multiple Order by One Oder Number. Please Contact with Database Administrator." })); } return(View(DuePaymentViewModel)); }