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 static decimal GetNewRentRate(InactiveLeaseDTO old) { var newRate = old.Rent.RegularRate * 1.10M; var rounding = MidpointRounding.AwayFromZero; return(Math.Round(newRate, 0, rounding)); }
public void RejectInactiveLeasetype() { var sut = new MockMarketState(); var lse = new InactiveLeaseDTO(); sut.Invoking(_ => _.DeactivateLease(lse, "", DateTime.Now)) .Should().Throw <InvalidStateException>(); }
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 Nullifinactivelease() { var sut = new RentMonthlySurcharger(); var lse = new InactiveLeaseDTO { Rent = new RentParams { PenaltyRule = sut.RuleName } }; var charges = sut.GetPenalties(lse, 6.May(2018), 123); charges.Should().BeNull(); }
public void Nullifinactivelease() { var sut = new RightsDailyAfter90Surcharger(); var lse = new InactiveLeaseDTO { Rights = new RightsParams { PenaltyRule = sut.RuleName } }; var charges = sut.GetPenalties(lse, 3.May(2018), 123); charges.Should().BeNull(); }
public void NonActiveInsertFails() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <InactiveLeaseDTO> >(); var sut = new InactiveLeasesRepo1(moq.Object, arg); var lse = new InactiveLeaseDTO(); arg.MoqActiveLeases.Setup(_ => _.HasId(lse.Id)).Returns(false); sut.Invoking(_ => _.Insert(lse)) .Should().Throw <InvalidInsertionException>(); }
public static InactiveLeaseDTO DeactivateLease(this MarketStateDbBase mkt, LeaseDTO lse, string reason, DateTime deactivationDate) { if (lse is InactiveLeaseDTO) { throw Bad.State <LeaseDTO>("Inactive", "Active"); } var inactv = new InactiveLeaseDTO(lse, reason, deactivationDate, mkt.CurrentUser); mkt.InactiveLeases.Insert(inactv); return(inactv); }
public void ErrorifrecordundeletedforActives() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <InactiveLeaseDTO> >(); var sut = new InactiveLeasesRepo1(moq.Object, arg); var lse = new InactiveLeaseDTO { Id = 1234 }; arg.MoqActiveLeases.SetupSequence(_ => _.HasId(lse.Id)).Returns(true) .Returns(true); sut.Invoking(_ => _.Insert(lse)) .Should().Throw <InvalidStateException>(); }
private static LeaseDTO CreateNewActive(InactiveLeaseDTO old, DateTime lastDte) { var lse = new LeaseDTO { Tenant = old.Tenant, Stall = old.Stall, ContractStart = lastDte.AddDays(1).Date, ContractEnd = old.ContractEnd, Rent = old.Rent, Rights = old.Rights, RenewedFromID = old.Id, ProductToSell = old.ProductToSell, Remarks = old.Remarks, }; lse.Rent.RegularRate = GetNewRentRate(old); lse.Rent.GracePeriodDays = 0; return(lse); }
public void InsertcallsBatchBalUpdateafterSave() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <InactiveLeaseDTO> >(); var bal = new Mock <IDailyBillsRepo>(); var sut = new InactiveLeasesRepo1(moq.Object, arg); var lse = new InactiveLeaseDTO { Id = 1234 }; arg.MoqActiveLeases.SetupSequence(_ => _.HasId(lse.Id)).Returns(true) .Returns(false); arg.MoqBalanceDB.Setup(_ => _.GetRepo(lse.Id)).Returns(bal.Object); sut.Insert(lse); bal.Verify(_ => _ .RecomputeFrom(lse.DeactivatedDate), Times.Once); }
public void InsertremovesfromActivesafterSave() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <InactiveLeaseDTO> >(); var sut = new InactiveLeasesRepo1(moq.Object, arg); var lse = new InactiveLeaseDTO { Id = 1234 }; arg.MoqActiveLeases.SetupSequence(_ => _.HasId(lse.Id)).Returns(true) .Returns(false); arg.MoqBalanceDB.Setup(_ => _.GetRepo(lse.Id)) .Returns(Mock.Of <IDailyBillsRepo>()); sut.Insert(lse); arg.MoqActiveLeases.Verify(_ => _.Delete(lse.Id), Times.Once()); }
public void ActiveInsertionreturnsrecwithsameID() { var arg = new MockMarketState(); var moq = new Mock <ISimpleRepo <InactiveLeaseDTO> >(); var sut = new InactiveLeasesRepo1(moq.Object, arg); var lse = new InactiveLeaseDTO { Id = 1234 }; arg.MoqActiveLeases.SetupSequence(_ => _.HasId(lse.Id)).Returns(true) .Returns(false); arg.MoqBalanceDB.Setup(_ => _.GetRepo(lse.Id)) .Returns(Mock.Of <IDailyBillsRepo>()); moq.Setup(_ => _.Insert(lse)).Returns(lse.Id); var rId = sut.Insert(lse); rId.Should().Be(lse.Id); }