public override IDocumentDTO CastByfToDTO(object byfRecord) { var byf = Cast(byfRecord); //if (byf.Id.Value == 4566788) //{ // var a = "DSAf"; //} var stall = _stalls?.Single(_ => _.Id == byf.Stall.Id.Value); var active = new LeaseDTO { Id = (int)byf.Id.Value, Tenant = byf.Tenant.CastTenant(), Stall = stall, ContractStart = byf.ContractStart.ToLocalTime(), ContractEnd = byf.ContractEnd.ToLocalTime(), ProductToSell = byf.ProductToSell.Trim().NullIfBlank(), Rent = byf.CastRentParams(), Rights = byf.CastRightsParams(), ApplicationSubmitted = byf.ApplicationSubmitted, Remarks = byf.Remarks.Trim().NullIfBlank(), }; //if (_terminations == null) return active; //if (_terminations.TryGetValue(byf.Id.Value, out DateTime termDate)) // return new InactiveLeaseDTO(active, "Terminated", termDate, "Migrator"); //else // return active; return(active.AsInactiveIfSo(_terminations, _lastClosedDate)); }
private static void RebuildSoaFor(LeaseDTO lse, DateTime minDate, ITenantDBsDir dir) { var repo = dir.Balances.GetRepo(lse); DeleteRowsEarlierThan(minDate, repo); repo.RecomputeFrom(minDate); }
private ActiveLeasesRepo1 CreateSUT(out LeaseDTO validSample) { var mkt = new Mock <IMarketStateDB>(); var moq = new Mock <ISimpleRepo <LeaseDTO> >(); var sut = new ActiveLeasesRepo1(moq.Object, mkt.Object); validSample = ValidSampleDTO(); moq.Setup(_ => _.Any()).Returns(true); moq.Setup(_ => _.Find(It.IsAny <int>(), true)).Returns(ValidSampleDTO()); moq.Setup(_ => _.GetAll()) .Returns(new List <LeaseDTO> { //new LeaseDTO { Stall = new StallDTO{ Id = OCCUPIED_BY_SAMPLE }}, new LeaseDTO { Stall = new StallDTO { Id = OCCUPIED_BY_ANOTHER } } }); return(sut); }
//public IDailyBillsRepo GetRepo(LeaseDTO lse) => GetRepo(lse.Id); public DailyBillDTO GetBill(LeaseDTO lse, DateTime date) { var repo = GetRepo(lse); var id = date.DaysSinceMin(); return(repo.Find(id, false)); }
protected override List <BillPenalty> GetPenaltiesList(LeaseDTO lse, DateTime date, decimal?oldBal) { if ((oldBal ?? 0) <= 0) { return(null); } if (!lse.IsActive(date)) { return(null); } var billDay = (int)Math.Round(lse.Rent.PenaltyRate2); if (date.Day != billDay + 1) { return(null); } var rate = lse.Rent.PenaltyRate1; return(new List <BillPenalty> { new BillPenalty { Label = RuleName, Amount = GetPenaltyAmount(oldBal.Value, rate), Computation = GetComputation(oldBal.Value, rate) } }); }
public void RefreshStall(LeaseDTO lease) { if (Stalls == null) { return; } if (lease == null) { throw Fault.NullRef("Lease"); } if (lease.Stall == null) { throw Fault.NullRef("Lease.Stall"); } //lease.Stall = Stalls.Find(lease.Stall.Id, true); var stallID = lease.Stall.Id; if (_stalls.TryGetValue(stallID, out StallDTO cached)) { lease.Stall = cached; } else { lease.Stall = Stalls.Find(stallID, true); //_stalls[stallID] = lease.Stall; try { _stalls?.Add(stallID, lease.Stall); } catch { } } }
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}]", }); } }
protected override List <BillPenalty> GetPenaltiesList(LeaseDTO lse, DateTime date, decimal?oldBal) { if ((oldBal ?? 0) <= 0) { return(null); } if (!lse.IsActive(date)) { return(null); } if (IsDayAfterDue(date, lse)) { return(Penalty(lse.Rights.PenaltyRate1, oldBal)); } else if (IsBeyond90Days(date, lse)) { return(Penalty(lse.Rights.PenaltyRate2, oldBal)); } else { return(null); } }
public LeaseRowVM(LeaseDTO leaseDTO, MainWindowVM2 mainWindowVM2) { Lease = leaseDTO; MainWindow = mainWindowVM2; RefreshCmd = R2Command.Async(LoadRntCell, _ => !IsBusy); UpdateRntCmd = R2Command.Async(UpdateRntDB, _ => !IsBusy, "Update RNT"); }
public static bool IsActive(this LeaseDTO lse, DateTime asOfDate) { asOfDate = asOfDate.Date; if (lse is InactiveLeaseDTO inactv) { if (asOfDate > inactv.DeactivatedDate) { return(false); } } if (lse.ContractStart > asOfDate) { return(false); } if (lse.ContractEnd < asOfDate) { return(false); } if (lse.Stall == null) { throw Fault.NullRef("Lease.Stall"); } if (!lse.Stall.IsOperational) { return(false); } return(true); }
private BillAmounts GetTarget(LeaseDTO lse) => new BillAmounts { Rent = GetDue(lse, BillCode.Rent), Rights = GetDue(lse, BillCode.Rights), Electric = GetDue(lse, BillCode.Electric), Water = GetDue(lse, BillCode.Water), };
public static void ReprocessBalancedDay(this LeaseDTO lse, DateTime startDate, ITenantDBsDir dir) { var endDate = lse.ContractStart; var bals = dir.MarketState.Balances.GetRepo(lse.Id); var secId = lse.Stall.Section.Id; foreach (var date in startDate.EachDayUpTo(endDate)) { var colxns = dir.Collections.For(date); if (colxns == null) { continue; } var intends = colxns.IntendedColxns[secId].GetAll(); var memos = colxns.BalanceAdjs.GetAll(); var cashrs = colxns.CashierColxns.GetAll(); if (intends.Any(_ => _.Lease.Id == lse.Id) || memos.Any(_ => _.LeaseId == lse.Id) || cashrs.Any(_ => _.Lease.Id == lse.Id)) { bals.ProcessBalancedDay(date); } } }
public override List<BillPenalty> ComputePenalties(LeaseDTO lse, DateTime date, decimal? previousBalance) { switch (lse.Rent.PenaltyRule) { case RentPenalty.DailySurcharge: return new RentDailySurcharger() .GetPenalties(lse, date, previousBalance); case RentPenalty.DailySurcharge_NoRoundOff: return new RentDailySurchargerNoRoundOff() .GetPenalties(lse, date, previousBalance); case RentPenalty.MonthlySurcharge: return new RentMonthlySurcharger() .GetPenalties(lse, date, previousBalance); case RentPenalty.ZeroSurcharge: return new RentZeroSurcharger() .GetPenalties(lse, date, previousBalance); case RentPenalty.ZeroBackrent: return new RentZeroBackrent() .GetPenalties(lse, date, previousBalance); default: throw Fault.BadArg(nameof(lse.Rent.PenaltyRule), lse.Rent.PenaltyRule); } }
public override IDailyBillsRepo GetRepo(LeaseDTO lse) { var file = Path.Combine(_foldrPath, GetFilename(lse.Id)); var db = new SharedLiteDB(file, _mkt.CurrentUser); return(new DailyBillsRepo1(lse, new DailyBillsCollection(db), _dir)); }
public CollectorDTO GetCollector(LeaseDTO lease) { if (lease.Stall.Section == null) { _mkt.RefreshStall(lease); } return(GetCollector(lease.Stall.Section)); }
public static void Show(LeaseDTO lse, ITenantDBsDir args) { if (lse == null || args == null) { return; } new SoaViewerVM(lse, args).Show <SoaViewerWindow>(); }
public SoaCellViewerVM(LeaseDTO leaseDTO, DateTime businessDate, BillState billState, ITenantDBsDir args) : base(args) { Lease = leaseDTO; Date = businessDate; Bill = billState; Adjustments = new AdjustmentsListVM(Lease.Id, Bill.BillCode, Date, AppArgs); Adjustments.TotalSumChanged += (s, e) => ReturnDialogResult(true); }
public DailyBillsRow(LeaseDTO leaseDTO, DailyBillDTO dailyBillDTO, Dictionary <int, CollectorDTO> collectorsDict) { _collectors = collectorsDict; Lease = leaseDTO; DTO = dailyBillDTO; Date = DTO.GetBillDate(); Labels = SetRowLabels(); Collector = SetCollector(); }
public static void UndoLeaseTermination(this MarketStateDbBase mkt, InactiveLeaseDTO inactiveLeaseDTO) { //todo: reject if stall is in use var activ = new LeaseDTO(); activ.CopyByNameFrom(inactiveLeaseDTO as LeaseDTO); mkt.ActiveLeases.Insert(activ); mkt.InactiveLeases.Delete(inactiveLeaseDTO); }
public void TestMethod00002() { var bal = -100; var dte = 27.May(2018); var lse = new LeaseDTO(); CollectorPerfSubRow.GetRightsTarget(bal, dte, lse) .Should().Be(0); }
public LeaseBalAdjustmentsVM(LeaseDTO lease, MainWindowVM2 mainWindowVM2) : base(mainWindowVM2.AppArgs) { Lease = lease; Main = mainWindowVM2; Rows = new LeaseBalAdjsList(); ImportCmd = R2Command.Async(_ => Rows.Import(this), null, "Import"); SetCaption($"{Lease}"); ClickRefresh(); }
public SoaViewerVM(LeaseDTO leaseDTO, ITenantDBsDir appArguments) : base(appArguments) { Lease = leaseDTO; UpdateBalanceFromDateCmd = R2Command.Async(UpdateBalanceFromDate, _ => AppArgs.CanForceLeaseBalanceUpdate(false), "Recompute Balances starting from this date"); SetCaption($"[{Lease.Id}] {Lease.TenantAndStall}"); Rows.ItemOpened += (s, e) => OnItemOpened(e); ClickRefresh(); }
public void ReturnsrecordwithsameId() { var sut = new MockMarketState(); var lse = new LeaseDTO { Id = 12345 }; var rec = sut.DeactivateLease(lse, "", DateTime.Now); rec.Should().NotBeNull(); rec.Id.Should().Be(lse.Id); }
protected override decimal GetRegularDue(LeaseDTO lse, DateTime date) { if (!lse.IsActive(date)) return 0; if (date.Date < lse.FirstRentDueDate.Date) return 0; switch (lse.Rent.Interval) { case BillInterval.Daily : return GetDailyDue (lse, date); case BillInterval.Monthly: return GetMonthlyDue (lse, date); default: throw Bad.Arg("Rent.Interval", lse.Rent.Interval); } }
private static void ExecuteRateIncrease(LeaseDTO origLse, ITenantDBsDir dir) { var mkt = dir.MarketState; var lastDte = 28.Feb(2019); var reason = "2019 Rate Increase"; var inactv = mkt.DeactivateLease(origLse, reason, lastDte); var newActv = CreateNewActive(inactv, lastDte); mkt.ActiveLeases.Insert(newActv); inactv.ForwardBalancesTo(newActv, dir); }
public override List <BillPenalty> ComputePenalties(LeaseDTO lse, DateTime date, decimal?previousBalance) { switch (lse.Rights.PenaltyRule) { case RightsPenalty.DailyAfter90Days: return(new RightsDailyAfter90Surcharger() .GetPenalties(lse, date, previousBalance)); default: throw Fault.BadArg(nameof(lse.Rights.PenaltyRule), lse.Rights.PenaltyRule); } }
public LeaseColxnRow(SectionDTO sec, AmbulantColxnDTO dto) { Lease = new LeaseDTO { Tenant = TenantModel.Named(dto.ReceivedFrom), Stall = StallDTO.Named($"{sec.Name} Section Ambulant") }; AmbulantDTO = dto; DocumentRef = dto.PRNumber?.ToString(); Ambulant = dto.Amount; Remarks = dto.Remarks; }
public void CallingDeletefails() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <LeaseDTO> >(); var sut = new ActiveLeasesRepo1(moq.Object, arg); var lse = new LeaseDTO(); arg.MoqInactiveLeases.Setup(_ => _.HasId(lse.Id)).Returns(false); sut.Invoking(_ => _.Delete(lse)) .Should().Throw <InvalidDeletionException>(); }
public List <BillAdjustment> ReadAdjustments(LeaseDTO lse, DateTime date) { var db = _colxnsDir.For(date); if (db == null) { return(new List <BillAdjustment>()); } return(db.BalanceAdjs.GetAll() .Where(_ => _.LeaseId == lse.Id && _.BillCode == this.BillCode) .Select(_ => _.ToBillAdjustment()).ToList()); }
public decimal GetTotalDue(LeaseDTO lse, BillState state, DateTime date) { if (state == null) { return(GetRegularDue(lse, date)); } else { return((state.OpeningBalance ?? 0) + state.TotalPenalties + state.TotalAdjustments + GetRegularDue(lse, date)); } }