Ejemplo n.º 1
0
 public static FinancialStats GetBalance(IMoneyCalculator calculator,
                                         FinancialStats income,
                                         FinancialStats expense)
 {
     return(new FinancialStats(
                calculator.Minus(income.Actual, expense.Actual),
                calculator.Minus(income.Forecast, expense.Forecast),
                calculator));
 }
        public AnnualBudgetReport(IMoneyCalculator calculator, IEnumerable <MonthlyBudgetReport> months)
        {
            Months = months.ToList();

            Income  = FinancialStats.GetTotal(calculator, Months.Select(n => n.Income));
            Expense = FinancialStats.GetTotal(calculator, Months.Select(n => n.Expense));

            Balance = FinancialStats.GetBalance(calculator, Income, Expense);
        }
Ejemplo n.º 3
0
        public static FinancialStats GetTotal(IMoneyCalculator calculator, IEnumerable <FinancialStats> items)
        {
            var list = items.ToList();

            return(new FinancialStats(
                       calculator.Sum(list.Select(n => n.Actual)),
                       calculator.Sum(list.Select(n => n.Forecast)),
                       calculator));
        }
Ejemplo n.º 4
0
 public static FinancialStats GetTotal(IMoneyCalculator calculator,
                                       IEnumerable <Money> actual,
                                       IEnumerable <Money> forecast)
 {
     return(new FinancialStats(
                calculator.Sum(actual),
                calculator.Sum(forecast),
                calculator));
 }
Ejemplo n.º 5
0
 private static IEnumerable <ExpenseCategoryReport> GetExpensesReport(IMoneyCalculator calculator,
                                                                      IEnumerable <Category> categories,
                                                                      MonthLog expenseLog)
 {
     return(categories.Select(category => new ExpenseCategoryReport(
                                  category,
                                  calculator,
                                  expenseLog
                                  )));
 }
 public ReportsQueryService(IUserContext userContext,
                            IMoneyCalculator moneyCalculator,
                            IQueryDispatcher queryDispatcher,
                            ICacheStorage cacheStorage)
 {
     _userContext     = userContext;
     _moneyCalculator = moneyCalculator;
     _queryDispatcher = queryDispatcher;
     _cacheStorage    = cacheStorage;
 }
Ejemplo n.º 7
0
        public AbstractAccount(ICustomer customer, AccountType accountType)
        {
            this._moneyCalculator = MoneyCalculatorFactory.MONEY_CALC_FACTORY.CreateCalculator(this.GetAccountType());
            this._validator = Validation.VALIDATOR;
            this._openDate = DateTime.Now;

            this.Customer = customer;

            this._accountType = accountType;

            this._balance = 0;
        }
Ejemplo n.º 8
0
        public MonthLog(BudgetLogType log,
                        YearMonth when,
                        IMoneyCalculator calculator,
                        IEnumerable <Transaction> actual = null,
                        IEnumerable <Forecast> forecast  = null)
        {
            When         = when;
            Transactions = actual?.Where(n => n.Log == log).ToList() ?? new List <Transaction>();
            Forecasts    = forecast?.Where(n => n.Log == log).ToList() ?? new List <Forecast>();

            Total = FinancialStats.GetTotal(calculator,
                                            Transactions.Select(n => n.Amount),
                                            Forecasts.Select(n => n.Amount));
        }
Ejemplo n.º 9
0
        public ExpenseCategoryReport(Category category,
                                     IMoneyCalculator calculator,
                                     MonthLog expenseLog)
        {
            CategoryKey = category.Key;
            Title       = category.Title;
            Description = category.Description;

            Total = FinancialStats.GetTotal(calculator,
                                            expenseLog.Transactions
                                            .Where(n => category.IsSameOrParentOf(n.CategoryKey))
                                            .Select(n => n.Amount),
                                            expenseLog.Forecasts
                                            .Where(n => category.IsSameOrParentOf(n.CategoryKey))
                                            .Select(n => n.Amount)
                                            );
        }
Ejemplo n.º 10
0
        public MonthlyBudgetReport(YearMonth when, IMoneyCalculator calculator,
                                   IEnumerable <Category> categories,
                                   MonthLog incomeLog,
                                   MonthLog expenseLog)
        {
            if (incomeLog.Log != BudgetLogType.Incomes)
            {
                throw new ArgumentException(nameof(incomeLog));
            }
            if (expenseLog.Log != BudgetLogType.Expenses)
            {
                throw new ArgumentException(nameof(expenseLog));
            }

            When = when;

            Income  = incomeLog.Total;
            Expense = expenseLog.Total;
            Balance = FinancialStats.GetBalance(calculator, Income, Expense);

            Expenses = GetExpensesReport(calculator, categories, expenseLog);
        }
Ejemplo n.º 11
0
        private static object GetPropertyValue(PropertyDataBindingInfo propertyBindingInfo, object val, Type type)
        {
            if (propertyBindingInfo.PropertyInfo.PropertyType == typeof(string))
            {
                return(val.ToString().Trim());
            }

            // check the rate
            if (propertyBindingInfo.PropertyInfo.PropertyType == typeof(decimal) && propertyBindingInfo.DataMapping.CaculatorType != null)
            {
                IMoneyCalculator cal = GetMoneyCalculator(propertyBindingInfo.DataMapping.CaculatorType);

                if (cal != null)
                {
                    val = cal.Calculate((decimal)val);
                }
                else
                {
                    throw new Exception("XFramework.DB实例对象Mapping时异常,异常信息:" + string.Format("Mapping对象:{0};属性名称:{1};计算类型:{2}", type.FullName, propertyBindingInfo.PropertyInfo.Name, propertyBindingInfo.DataMapping.CaculatorType.FullName));
                }
            }
            return(val);
        }
Ejemplo n.º 12
0
 public void Setup()
 {
     _moneyCalculator = new MoneyCalculator();
 }
 public MonthLogQueryService(IMoneyCalculator moneyCalculator, IQueryDispatcher queryDispatcher)
 {
     _moneyCalculator = moneyCalculator;
     _queryDispatcher = queryDispatcher;
 }
Ejemplo n.º 14
0
 public FinancialStats(Money actual, Money forecast, IMoneyCalculator calculator)
 {
     Forecast   = forecast;
     Actual     = actual;
     Difference = calculator.Minus(Actual, Forecast);
 }