private void GenerateTellerEvents(OCurrency amount, bool isOpen) { if (isOpen) { OpenOfDayAmountEvent.Amount = amount; OpenOfDayAmountEvent.TellerId = _teller.Id; OpenOfDayAmountEvent.Date = TimeProvider.Now; OCurrency expectedOpeningBalance = ServicesProvider.GetInstance().GetTellerServices().GetTellerBalance(_teller); OCurrency cashAmount = decimal.Parse(tbAmount.Text); if (expectedOpeningBalance < cashAmount) { OpenAmountPositiveDifferenceEvent = new OpenAmountPositiveDifferenceEvent(); OpenAmountPositiveDifferenceEvent.TellerId = _teller.Id; OpenAmountPositiveDifferenceEvent.Date = TimeProvider.Now; OpenAmountPositiveDifferenceEvent.Amount = cashAmount - expectedOpeningBalance; } else if (expectedOpeningBalance > cashAmount) { OpenAmountNegativeDifferenceEvent = new OpenAmountNegativeDifferenceEvent(); OpenAmountNegativeDifferenceEvent.TellerId = _teller.Id; OpenAmountNegativeDifferenceEvent.Date = TimeProvider.Now; OpenAmountNegativeDifferenceEvent.Amount = expectedOpeningBalance - cashAmount; } } else { CloseOfDayAmountEvent.Amount = amount; CloseOfDayAmountEvent.TellerId = Teller.CurrentTeller.Id; CloseOfDayAmountEvent.Date = TimeProvider.Now; OCurrency excpectedClosingBalance = ServicesProvider.GetInstance().GetTellerServices().GetTellerBalance(_teller); excpectedClosingBalance += ServicesProvider.GetInstance().GetTellerServices().GetLatestTellerOpenBalance(_teller); OCurrency cashAmount = decimal.Parse(tbAmount.Text); if (excpectedClosingBalance < cashAmount) { CloseAmountPositiveDifferenceEvent = new CloseAmountPositiveDifferenceEvent(); CloseAmountPositiveDifferenceEvent.Amount = cashAmount - excpectedClosingBalance; CloseAmountPositiveDifferenceEvent.TellerId = Teller.CurrentTeller.Id; CloseAmountPositiveDifferenceEvent.Date = TimeProvider.Now; } else if (excpectedClosingBalance > cashAmount) { CloseAmountNegativeDifferenceEvent = new CloseAmountNegativeDifferenceEvent(); CloseAmountNegativeDifferenceEvent.Amount = excpectedClosingBalance - cashAmount; CloseAmountNegativeDifferenceEvent.TellerId = Teller.CurrentTeller.Id; CloseAmountNegativeDifferenceEvent.Date = TimeProvider.Now; } } }
private static TellerEvent GetTellerEvent(string code) { TellerEvent e; switch (code) { case OTellerEvents.CashIn: e = new TellerCashInEvent(); break; case OTellerEvents.CashOut: e = new TellerCashOutEvent(); break; case OTellerEvents.OpenDay: e = new OpenOfDayAmountEvent(); break; case OTellerEvents.CloseDay: e = new CloseOfDayAmountEvent(); break; case OTellerEvents.OpenDayPositiveDifference: e = new OpenAmountPositiveDifferenceEvent(); break; case OTellerEvents.OpenDayNegativeDifference: e = new OpenAmountNegativeDifferenceEvent(); break; case OTellerEvents.CloseDayPositiveDifference: e = new CloseAmountPositiveDifferenceEvent(); break; case OTellerEvents.CloseDayNegativeDifference: e = new CloseAmountNegativeDifferenceEvent(); break; default: Debug.Fail("Failed to create teller events"); throw new Exception(); } return e; }