Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        public static void ImportPaymentTypes(OleDbConnection con, AriClinicContext ctx)
        {
            //(1) Borrar antiguas formas de pago
            ctx.Delete(ctx.PaymentMethods);
            ctx.SaveChanges();

            //(2) Lleer todos los pacientes en OFT
            string sql = "SELECT * FROM FormaPago";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConFPago");
            int nreg = ds.Tables["ConFPago"].Rows.Count;
            int reg = 0;
            foreach (DataRow dr in ds.Tables["ConFPago"].Rows)
            {
                reg++;
                Console.WriteLine("Formas de pago {0:#####0} de {1:#####0} {2}", reg, nreg, (string)dr["NomFormaPago"]);
                PaymentMethod pm = (from pme in ctx.PaymentMethods
                                    where pme.OftId == (int)dr["IdFormaPago"]
                                    select pme).FirstOrDefault<PaymentMethod>();
                if (pm == null)
                {
                    pm = new PaymentMethod();
                    ctx.Add(pm);
                }
                pm.Name = (string)dr["NomFormaPago"];
                pm.OftId = (int)dr["IdFormaPago"];
            }
            ctx.SaveChanges();
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static void ImportPaymentTypes(OleDbConnection con, AriClinicContext ctx)
        {
            //(1) Borrar antiguas formas de pago
            ctx.Delete(ctx.PaymentMethods);

            //(2) Lleer todos los pacientes en OFT
            string sql = "SELECT * FROM FormaPago";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConFPago");
            int nreg = ds.Tables["ConFPago"].Rows.Count;
            int reg = 0;
            foreach (DataRow dr in ds.Tables["ConFPago"].Rows)
            {
                PaymentMethod pm = new PaymentMethod();
                pm.Name = (string)dr["NomFormaPago"];
                pm.OftId = (int)dr["IdFormaPago"];
                ctx.Add(pm);
            }
            ctx.SaveChanges();
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public static bool PayNote(PaymentMethod pm, Decimal amount, DateTime dt, string des, ServiceNote note, Clinic cl, GeneralPayment gp, AriClinicContext ctx)
 {
     Payment p = null; // payment to be created
     Ticket t = null; // related ticket
     //(0) Control if amount > pending in note
     decimal total_paid = 0;
     foreach (Ticket tk in note.Tickets)
         total_paid += tk.Paid;
     if ((note.Total - total_paid) < amount)
         return false; // amount bigger than debt.
          
     //(1) Look for a ticket (inside note) with the same amount
     t = (from tk in note.Tickets
          where (tk.Amount - tk.Paid) == amount
          select tk).FirstOrDefault<Ticket>();
     if (t != null)
     {
         // (1.1) It exists.
         CreatePayment(t, pm, amount, dt, des, note, cl, gp, ctx);
     }
     else
     {
         // (1.2) It doesn't exist
         var rs = from tk in note.Tickets
                  orderby (tk.Amount - tk.Paid)
                  select tk;
         foreach (Ticket tk in rs)
         {
             if (tk.Amount - tk.Paid >= amount)
             {
                 CreatePayment(tk, pm, amount, dt, des, note, cl, gp, ctx);
                 break; // out
             }
             else
             {
                 decimal paid = tk.Amount - tk.Paid;
                 amount = amount - paid;
                 CreatePayment(tk, pm, paid, dt, des, note, cl, gp, ctx);
             }
         }
     }
     ctx.SaveChanges();
     return true;
 }