public IActionResult PostInvoicePayments() { Users user = new Users { Id = long.Parse(HttpContext.User.FindFirst(ClaimTypes.Actor).Value) }; Invoice invoice = IFinanceService.GetInvoice(InvoiceModel.Invoice.Id); InvoicePayment payment = InvoiceModel.Payment; if (payment.Amount > invoice.Balance) { return(LocalRedirect("/billing/invoice/?qp=" + invoice.Id + "&error=4501&amts=" + payment.Amount)); } payment.Invoice = invoice; payment.CreatedBy = user; payment.Notes = "N/A"; payment.Save(); foreach (var details in InvoiceModel.Payments) { if (details.Amount.Equals(0)) { continue; } details.Payment = payment; details.Save(); } invoice.Paid += payment.Amount; invoice.Balance += payment.Amount; invoice.SetAutoFlag(); return(LocalRedirect("/billing/invoice/?qp=" + invoice.Id)); }
public IActionResult RegisterVisit() { Users user = new Users { Id = Int64.Parse(HttpContext.User.FindFirst(ClaimTypes.Actor).Value) }; Patient patient = VisitModel.Visit.Patient; patient.Status = new PatientStatus { Id = Constants.STATUS_ACTIVE }; patient.UpdateStatus(); Encounter encounter = new Encounter { Type = new EncounterType { Id = Constants.ENCOUNTER_VISIT }, Patient = patient, CreatedBy = user }; encounter.Create(IPatientService); Visit visit = VisitModel.Visit; visit.Type = new VisitType { Id = Constants.VISIT_FACILITY }; visit.CreatedBy = user; visit.CreatedOn = DateTime.Now; visit.Save(); Referral referral = VisitModel.Referral; if (!referral.Type.Id.Equals(0)) { referral.Visit = visit; referral.CreatedBy = user; referral.Save(); var seps = new string[] { "," }; string[] doctors = VisitModel.DoctorString.Split(seps, StringSplitOptions.RemoveEmptyEntries); foreach (string doc in doctors) { new ReferralDoctors { Referral = referral, Doctor = new Doctor { Id = Convert.ToInt64(doc) } }.Save(); } } Bills bill = VisitModel.Bill; bill.Visit = visit; bill.Department = new Department { Id = Constants.DEPT_REGISTRATION }; bill.CreatedBy = user; bill.Save(); if (VisitModel.Waiver) { bill.Waiver = bill.Amount; bill.WaiverReason = VisitModel.WaiverReason; bill.WaivedBy = user; bill.UpdateWaiver(); bill.Flag = new BillingFlag { Id = Constants.FLAG_CLEARED }; bill.ProcessedBy = user; bill.UpdateProcess(); } BillsItem item = VisitModel.Item; item.Bill = bill; item.CreatedBy = user; item.Save(); //INVOICE/FLAG/CLEAR if (VisitModel.Waiver) { Invoice invoice = new Invoice { Patient = patient, Flag = new BillingFlag { Id = Constants.FLAG_CLEARED }, CreatedBy = user, Notes = "Waivered Bill" }; invoice.Save(); InvoiceDetails details = new InvoiceDetails { Invoice = invoice, Item = item, CreatedBy = user, Notes = "Waivered Item" }; details.Save(); InvoicePayment payment = new InvoicePayment { Invoice = invoice, CreatedBy = user, Notes = "Waiver Payment" }; payment.Save(); InvoicePaymentDetails pd = new InvoicePaymentDetails { Mode = new BillingMode { Id = Constants.MODE_WAIVER }, Reference = "CASHIER-00", Amount = bill.Amount, Notes = "Waiver Payment" }; pd.Save(); } Queues queue = VisitModel.Queue; queue.Visit = visit; queue.Item = item; queue.CreatedBy = user; queue.Save(); return(LocalRedirect("/registration/search")); }