public static void PaymentDelete(Payment pay, AriClinicContext ctx) { // minus paid in ticket if (pay.Ticket != null) { pay.Ticket.Paid = pay.Ticket.Paid - pay.Amount; } ctx.Delete(pay); ctx.SaveChanges(); }
public static GeneralPayment GeneralPaymentNew(Clinic clinic, ServiceNote sn, decimal amount, PaymentMethod payMethod, DateTime payDate, string description, AriClinicContext ctx) { var rs = from t in sn.Tickets where t.Amount > t.Paid select t; GeneralPayment gp = new GeneralPayment(); gp.ServiceNote = sn; gp.PaymentDate = payDate; gp.Description = description; gp.PaymentMethod = payMethod; gp.Amount = amount; gp.Clinic = clinic; ctx.Add(gp); foreach (Ticket t in rs.OrderByDescending(tk => tk.Amount - tk.Paid)) { Payment pay = new Payment(); pay.PaymentMethod = payMethod; pay.PaymentDate = payDate; pay.Ticket = t; pay.GeneralPayment = gp; pay.Description = description; pay.Clinic = clinic; decimal dif = t.Amount - t.Paid; if (dif <= amount) { pay.Amount = dif; amount = amount - dif; t.Paid = t.Paid + dif; } else { pay.Amount = amount; t.Paid = t.Paid + amount; amount = 0; } ctx.Add(pay); if (amount == 0) break; } ctx.SaveChanges(); return gp; }
public static bool PaymentControl(Ticket tck, Payment pay, decimal amount) { decimal thisAmount = 0; if (pay != null) thisAmount = pay.Amount; if (((tck.Paid - thisAmount) + amount) > tck.Amount) return false; else return true; }
public static void CreatePayment(Ticket t, PaymentMethod pm, Decimal amount, DateTime dt, string des, ServiceNote note, Clinic cl, GeneralPayment gp, AriClinicContext ctx) { // Now we need verify if there's a payment yet with the same values Payment p = new Payment(); p.Amount = amount; p.Clinic = cl; p.PaymentDate = dt; p.PaymentMethod = pm; p.GeneralPayment = gp; p.Description = des; p.Ticket = t; t.Paid = t.Paid + amount; ctx.Add(p); }