예제 #1
0
파일: Form1.cs 프로젝트: JosPlays/YNAB
        private void btnSpendByPayee_Click(object sender, System.EventArgs e)
        {
            var payeesApi = new PayeesApi();
            var payees    = payeesApi.GetPayees(_selectedBudget.Id);

            List <PaidPerPayeeModel> models         = new List <PaidPerPayeeModel>();
            TransactionsApi          transactionApi = new TransactionsApi();

            foreach (var payee in payees.Data.Payees)
            {
                PaidPerPayeeModel newModel = new PaidPerPayeeModel();
                var transactions           = transactionApi.GetTransactionsByPayee(_selectedBudget.Id, payee.Id, null, string.Empty);
                newModel.Name = payee.Name;
                foreach (var transaction in transactions.Data.Transactions)
                {
                    double transAsDecimal = Convert.ToDouble(transaction.Amount) / 1000;
                    if (transaction.Amount != null)
                    {
                        newModel.TotalSpend += transAsDecimal;
                    }
                }

                models.Add(newModel);
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"test.csv"))
            {
                file.WriteLine($"\"Name\";\"Total Spend\"");
                foreach (var model in models)
                {
                    if (model.TotalSpend >= 0 || model.Name.StartsWith("Transfer :"))
                    {
                        continue;
                    }

                    file.WriteLine($"\"{model.Name}\";\"{model.TotalSpend}\"");
                }
            }
        }