private void processPayment(ProcessInput input) { var userid = Context.GetUser(); var emp = (from empl in Employee where empl.employeeid == userid select empl).FirstOrDefault(); var emplog = (from empl in EmployeeLoginMapping where empl.employeeid == userid select empl).FirstOrDefault(); if (emp.divisionid != null) { var bgd = (from bg in BillGroupDetail where bg.Id == input.GroupId select bg).FirstOrDefault(); if (bgd == null) { throw new Exception("Bill Group Not Generated"); } var now = DateTime.Now; var qry = from bill in Bill join us in UnitSummary on bill.UnitId equals us.id where us.divisionid == emp.divisionid && us.billgroupid == bgd.BillGroupId && bill.MonthYear == input.MonthYear join pay in PaymentDetail on bill.Id equals pay.BillNo into pd from p in pd.DefaultIfEmpty() //from p in pd.Where(o=>o.Canceled==false).DefaultIfEmpty() //where p.Canceled == false group new { Bill = bill, Pay = p } by bill.Id into g select new PaymentProcess { Amount = g.First().Bill.TotalAmount, BillNo = g.First().Bill.Id, Paid = g.Sum(p => p.Pay == null ? 0 : p.Pay.Canceled ?0 : p.Pay.Amount), }; var qryLst = qry.ToList(); foreach (var item in qryLst) { item.Balance = Convert.ToDouble(item.Paid) - item.Amount; item.OverPay = item.Balance > 0; item.ProcessedAt = DateTime.Now; item.ProcessedBy = emplog.loginname; } PaymentProcess.AddRange(qryLst); bgd.Status = "Closed"; BillGroupDetail.Update(bgd); this.SaveChanges(); } }
public string UpdateBillGroupItem(BillGroupDetail input) { var result = "Success"; try { var item = (from bg in BillGroupDetail where bg.Id == input.Id select bg).FirstOrDefault(); if (item != null) { item.DueDate = input.DueDate; item.BillDate = input.BillDate; BillGroupDetail.Update(item); this.SaveChanges(); } } catch (Exception ex) { return("Failed :" + ex.Message); } return(result); }
public string GenerateBillBGWise(long BillGroupDetailId) { var result = "Success"; var billsToAdd = new List <Bill>(); var bgDetail = GetBillGroup(BillGroupDetailId); var monthYear = bgDetail.BillMonth.ToString("00") + bgDetail.BillYear.ToString(); var units = from unit in UnitSummary where unit.billgroupid == bgDetail.BillGroupId && unit.divisionid == bgDetail.DivisionId select unit; var exist = (from bill in Bills join ui in units on bill.UnitId equals ui.id where bill.MonthYear == monthYear select ui).Any(); if (exist) { return("Already Bill Generated for this Period."); } foreach (var unit in units.ToList()) { billsToAdd.Add(GenerateBillForUnit(bgDetail, unit, monthYear)); } Bills.AddRange(billsToAdd); SaveChanges(); var bgd = (from bg in BillGroupDetail where bg.Id == BillGroupDetailId select bg).FirstOrDefault(); bgd.Status = "Generated"; BillGroupDetail.Update(bgd); SaveChanges(); return(result); }