コード例 #1
0
        public bool SendFunds(decimal amount, DateTime date, string note)
        {
            var withdrawal = new Transactions(-amount, date, note);

            AllTransaction.Add(withdrawal);

            Console.WriteLine("Transfer Successful");
            return(true);
        }
コード例 #2
0
        public void ReceiveMoney(decimal amount, DateTime date, string note)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), "Amount of deposit must be positive");
            }
            var deposit = new Transactions(amount, date, note);

            AllTransaction.Add(deposit);
        }
コード例 #3
0
        /// <summary>
        ///     Get a list with income, spending and earnings for current month
        /// </summary>
        /// <returns>List with income, spending and earning item.</returns>
        public static ObservableCollection <StatisticItem> GetMonthlyCashFlow()
        {
            var transactionListFunc =
                new Func <List <FinancialTransaction> >(() =>
                                                        AllTransaction
                                                        .Where(x => x.Type != (int)TransactionType.Transfer)
                                                        .Where(x => x.Date.Month == DateTime.Now.Month)
                                                        .ToList());

            return(GetCashFlowStatisticItems(transactionListFunc));
        }
コード例 #4
0
        /// <summary>
        ///     Get a list with income, spending and earnings for custom date range
        /// </summary>
        /// <returns>List with income, spending and earning item.</returns>
        public static ObservableCollection <StatisticItem> GetMonthlyCashFlow(DateTime startDate, DateTime endDate)
        {
            var transactionListFunc =
                new Func <List <FinancialTransaction> >(() =>
                                                        AllTransaction
                                                        .Where(x => x.Type != (int)TransactionType.Transfer)
                                                        .Where(x => x.Date >= startDate.Date && x.Date <= endDate.Date)
                                                        .ToList());

            return(GetCashFlowStatisticItems(transactionListFunc));
        }
コード例 #5
0
        public override bool Withdrawal(decimal amount, DateTime date, string note)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), "Amount of withdrawal must be positive");
            }
            if (Balance - amount < 1000)
            {
                throw new InvalidOperationException("Not sufficient funds for this withdrawal");
            }
            var withdrawal = new Transactions(-amount, date, note);

            AllTransaction.Add(withdrawal);
            return(true);
        }
コード例 #6
0
        private static void IncludeIncome(IEnumerable <StatisticItem> statisticList)
        {
            foreach (StatisticItem statisticItem in statisticList)
            {
                statisticItem.Value -= AllTransaction
                                       .Where(x => x.Type == (int)TransactionType.Income)
                                       .Where(x => x.Category != null)
                                       .Where(x => x.Category.Name == statisticItem.Category)
                                       .Sum(x => x.Amount);

                SetLabel(statisticItem);

                if (statisticItem.Value <= 0)
                {
                    statisticItem.Value = 0;
                }
            }
        }
コード例 #7
0
ファイル: TransactionViewModel.cs プロジェクト: domerobi/PFM
        /// <summary>
        /// Search for transactions filtered by the given parameters
        /// </summary>
        /// <param name="selected">If it is given, then after search set the selected transaction to this parameter</param>
        private void Search(Transactions selected)
        {
            // calculate the balance after each transaction without filtering the categories
            CalculateCumulativeBalance(StartDate, EndDate);
            using (var db = new DataModel())
            {
                Transactions = new ObservableCollection <Transactions>(
                    AllTransaction
                    .Where(t => (SearchCategoryDirection.DirectionID == 0 ||
                                 t.Categories.CategoryDirections.DirectionID == SearchCategoryDirection.DirectionID) &&
                           (SearchCategory.CategoryID < 1 || t.CategoryID == SearchCategory.CategoryID)));
            }

            if (selected != null)
            {
                SelectedTransaction = Transactions.FirstOrDefault(t => t.TransactionID == selected.TransactionID);
            }
        }
コード例 #8
0
        /// <summary>
        ///     Returns spreading with custom date range
        /// </summary>
        /// <param name="startDate">minimum date</param>
        /// <param name="endDate">max date</param>
        /// <returns>List with statistic items.</returns>
        public static ObservableCollection <StatisticItem> GetSpreading(DateTime startDate, DateTime endDate)
        {
            if (AllTransaction == null)
            {
                TransactionData.LoadList();
            }

            if (AllCategories == null)
            {
                CateogryData.LoadList();
            }

            var transactionListFunc =
                new Func <List <FinancialTransaction> >(() =>
                                                        AllTransaction
                                                        .Where(x => x.Category != null)
                                                        .Where(x => x.Date >= startDate.Date && x.Date <= endDate.Date)
                                                        .Where(x => x.Type == (int)TransactionType.Spending)
                                                        .ToList());

            return(GetSpreadingStatisticItems(transactionListFunc));
        }
コード例 #9
0
        /// <summary>
        ///     Returns a list with a summary per category for the selected date range.
        /// </summary>
        /// <param name="startDate">start date</param>
        /// <param name="endDate">enddate</param>
        /// <returns>List with statistic Items.</returns>
        public static ObservableCollection <StatisticItem> GetCategorySummary(DateTime startDate, DateTime endDate)
        {
            var categories = new ObservableCollection <StatisticItem>();

            foreach (var category in AllCategories)
            {
                categories.Add(new StatisticItem {
                    Category = category.Name,
                    Value    = AllTransaction
                               .Where(x => x.Date.Date >= startDate.Date && x.Date.Date <= endDate.Date)
                               .Where(x => x.CategoryId == category.Id)
                               .Where(x => x.Type != (int)TransactionType.Transfer)
                               .Sum(x => x.Type == (int)TransactionType.Spending
                            ? -x.Amount
                            : x.Amount),
                    Label = ServiceLocator.Current.GetInstance <SettingDataAccess>().DefaultCurrency
                });
            }

            return(new ObservableCollection <StatisticItem>(
                       categories.Where(x => Math.Abs(x.Value) > 0.1).OrderBy(x => x.Value).ToList()));
        }
コード例 #10
0
        private void mnuTabTransaction_Click(object sender, RoutedEventArgs e)
        {
            AllTransaction allTran = new AllTransaction();

            AddTab(allTran);
        }
コード例 #11
0
        SimTransactionModel RunSimulate()
        {
            DateTime dt         = new DateTime(2000, 01, 01);
            Random   random_buy = new Random(Guid.NewGuid().GetHashCode());

            TransactionHold = new List <Transaction>();
            AllTransaction.Sort();
            HoldCapital = InitialCapital;
            int InvestTime = 0;
            int Win        = 0;
            int Loss       = 0;

            for (; dt < DateTime.Now; dt = dt.AddDays(1))
            {
                foreach (var HoldStock in TransactionHold)
                {
                    if (dt.Date.CompareTo(HoldStock.SellDetail.Date) == 0)
                    {
                        HoldCapital += double.Parse(HoldStock.SellDetail.Price.ToString()) * 1000;
                        InvestTime++;

                        if (HoldStock.Result.RateOfReturn > 0.5m)
                        {
                            Win++;
                        }
                        else
                        {
                            Loss++;
                        }
                    }
                }

                foreach (var all_transaction in AllTransaction)
                {
                    int randombuynumber = random_buy.Next(1000000);

                    //if (dt.Date.CompareTo(all_transaction.BuyDetail.Date) > 0)
                    //    break;


                    if (dt.Date.CompareTo(all_transaction.BuyDetail.Date) == 0)// &&
                    {
                        if (randombuynumber % BuyFreq == 0)
                        {//&&
                            if (HoldCapital >= double.Parse(all_transaction.BuyDetail.Price.ToString()) * 1000)
                            {
                                HoldCapital -= double.Parse(all_transaction.BuyDetail.Price.ToString()) * 1000;
                                TransactionHold.Add(all_transaction);
                            }
                        }
                    }
                }
            }


            SimTransactionModel sim = new SimTransactionModel();

            sim.InvestTimes               = InvestTime;
            sim.EndCapital                = HoldCapital;
            sim.ReturnofInvestment        = Math.Round((((HoldCapital - InitialCapital) / InitialCapital)) * 100, 2);
            sim.AverageReturnofInvestment = Math.Round((sim.ReturnofInvestment / sim.InvestTimes), 4);
            sim.Win      = Win;
            sim.Loss     = Loss;
            sim.WinRatio = Math.Round(((double)Win / (double)(Win + Loss) * 100), 2);


            return(sim);
        }
コード例 #12
0
        public async Task <long> InsertTransactionAsync(AllTransaction transaction)
        {
            using (var DBtransaction = context.Database.BeginTransaction())
            {
                try
                {
                    if (transaction.TransactionTypeId == 4)
                    {
                        var currentBal = await context.Users.Where(aa => aa.UserId == transaction.UserId).Select(aa => aa.CurrentBal).FirstOrDefaultAsync();

                        transaction.CurrentBal = currentBal;
                        await context.AllTransactions.AddAsync(transaction);

                        long transactionID = await context.SaveChangesAsync();

                        if (transactionID > 0)
                        {
                            await context.PaymentTransactions.AddAsync(new PaymentTransaction
                            {
                                CreatedDate       = DateTime.Now,
                                TransactionAmount = transaction.TransactionAmount,
                                TransactionId     = transactionID,
                                UserID            = transaction.CreatedBy
                            });

                            long paymnetId = await context.SaveChangesAsync();

                            if (paymnetId > 0)
                            {
                                await DBtransaction.CommitAsync();
                            }
                            else
                            {
                                await DBtransaction.RollbackAsync();
                            }
                            return(transactionID);
                        }
                    }
                    else if (transaction.TransactionTypeId == 3)
                    {
                        var currentBal = await context.Users.Where(aa => aa.UserId == transaction.UserId).Select(aa => aa.CurrentBal).FirstOrDefaultAsync();

                        transaction.CurrentBal = currentBal;
                        await context.AllTransactions.AddAsync(transaction);

                        long transactionID = await context.SaveChangesAsync();

                        if (transactionID > 0)
                        {
                            await DBtransaction.CommitAsync();

                            return(transactionID);
                        }
                        else
                        {
                            await DBtransaction.RollbackAsync();
                        }
                    }
                    return(0);
                }
                catch (Exception ex)
                {
                    await DBtransaction.RollbackAsync();

                    throw;
                }
            }
        }