public List <CreditStatemententity> Getcreditstatement(int?id, int userid) { List <CreditStatemententity> list = new List <CreditStatemententity>(); if (id != null) { using (var db = new EventDBEntities()) { var records = db.EventCustomers.Where(x => x.Evententryid == id).ToList(); if (records.Count > 1) { var noofcustomers = records.Count; var totalamount = db.EventEntryMasters.Find(id).TotalAmount; var userpaidamt = records.Where(x => x.Eventcustomerid == userid).FirstOrDefault().Paidamount; records = records.Where(x => x.Eventcustomerid != userid).ToList(); var equalamt = totalamount / noofcustomers; if (userpaidamt < equalamt)//if user paid less than divided amt { var userremainpaidamt = equalamt - userpaidamt; foreach (var item in records) { CreditStatemententity entity = new CreditStatemententity(); if (item.Paidamount > equalamt) { if (userremainpaidamt > 0) { var creditpaidamt = item.Paidamount - equalamt; if (userremainpaidamt <= creditpaidamt) { entity.creditamount = (decimal)userremainpaidamt; entity.creditby = item.UserMaster.Fullname; list.Add(entity); userremainpaidamt = 0; break; } else { userremainpaidamt = userremainpaidamt - creditpaidamt; entity.creditamount = (decimal)creditpaidamt; entity.creditby = item.UserMaster.Fullname; list.Add(entity); } } } } } } } } return(list); }
public List <CreditStatemententity> getcreditdetail(int?id, int userid) { List <CreditStatemententity> list = new List <CreditStatemententity>(); using (var db = new EventDBEntities()) { var records = db.CreditAmountDetails.Where(x => x.evententryid == id && x.Creditedto == userid).ToList(); foreach (var item in records) { CreditStatemententity entity = new CreditStatemententity(); entity.creditamount = (decimal)item.Creditamount; var creditedname = db.UserMasters.Find(item.Creditedfrom).Fullname; entity.creditby = creditedname; list.Add(entity); } } return(list); }