public static void ForwardBalancesTo(this InactiveLeaseDTO inactv, LeaseDTO newLse, ITenantDBsDir dir) { var adjDate = dir.Collections.UnclosedDate(); var newAdjs = dir.Collections.For(adjDate).BalanceAdjs; var oldAdjs = dir.Collections.For(inactv.DeactivatedDate).BalanceAdjs; var oldBills = dir.Balances.GetRepo(inactv).Latest(); foreach (var billCode in BillCodes.Collected()) { var oldBal = oldBills.For(billCode); if ((oldBal.ClosingBalance ?? 0) == 0) { continue; } newAdjs.Insert(new BalanceAdjustmentDTO { AmountOffset = oldBal.ClosingBalance.Value, BillCode = billCode, DocumentRef = "-", LeaseId = newLse.Id, Reason = $"Forwarded Balance from [{inactv.Id}]", }); oldAdjs.Insert(new BalanceAdjustmentDTO { AmountOffset = oldBal.ClosingBalance.Value * -1, BillCode = billCode, DocumentRef = "-", LeaseId = inactv.Id, Reason = $"Forwarded Balance to [{newLse.Id}]", }); } }
private List <DailyBillDTO> GetRecomputedFrom(DateTime date) { var minID = date.DaysSinceMin(); var matches = _repo.Find(_ => _.Id >= minID); //if (matches == null || !matches.Any()) return null; //var oldRows = matches.OrderBy(_ => _.Id).ToList(); //var maxDate = oldRows.Last ().GetBillDate(); var oldRows = new List <DailyBillDTO>(); var maxDate = date; if (matches?.Any() ?? false) { oldRows = matches.OrderBy(_ => _.Id).ToList(); maxDate = oldRows.Last().GetBillDate(); } foreach (var billCode in BillCodes.Collected()) { var openingBal = Find(date.AddDays(-1).DaysSinceMin(), false) ?.For(billCode)?.ClosingBalance; foreach (var rowDate in date.EachDayUpTo(maxDate)) { var newState = _billr.ComputeBill(billCode, _lse, rowDate, openingBal); var dto = oldRows.SingleOrDefault(_ => _.Id == rowDate.DaysSinceMin()); if (dto == null) { dto = DailyBillDTO.CreateFor(rowDate); oldRows.Add(dto); } if (dto.Bills == null) { dto.Bills = new List <DailyBillDTO.BillState>(); } dto.Bills.RemoveAll(_ => _.BillCode == billCode); dto.Bills.Add(newState); openingBal = newState.ClosingBalance; } } return(oldRows.OrderBy(_ => _.Id).ToList()); }
public void ProcessBalancedDay(DateTime balancedDay) { var nextDay = balancedDay.AddDays(1); Delete(nextDay.DaysSinceMin()); Insert(DailyBillDTO.CreateFor(nextDay)); var startId = _lse.ContractStart.DaysSinceMin(); var recompDate = _repo.HasId(startId) ? balancedDay : _lse.ContractStart; var dtos = GetRecomputedFrom(recompDate); if (dtos == null) { return; } foreach (var billCode in BillCodes.Collected()) { dtos.Last().For(billCode).ClosingBalance = null; } //_repo.Update(dtos, true); _repo.Upsert(dtos, true); }
public CashierColxnCrudVM(ICashierColxnsRepo repository, ITenantDBsDir appArguments) : base(repository, appArguments) { Leases.SetItems(GetSortedLeases()); BillCodes.SetItems(EnumTool.List <BillCode>()); }