Пример #1
0
        private string CreateCsv(TransactionListViewModel tlvm)
        {
            StringBuilder csv = new StringBuilder(8192);

            csv.Append(EscapeCsvValue(_localizer["ChargePointId"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["Connector"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StartTime"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StartTag"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StartMeter"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StopTime"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StopTag"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["StopMeter"]));
            csv.Append(CSV_Seperator);
            csv.Append(EscapeCsvValue(_localizer["ChargeSum"]));

            if (tlvm != null && tlvm.Transactions != null)
            {
                foreach (Transaction t in tlvm.Transactions)
                {
                    string startTag = t.StartTagId;
                    string stopTag  = t.StopTagId;
                    if (!string.IsNullOrEmpty(t.StartTagId) && tlvm.ChargeTags != null && tlvm.ChargeTags.ContainsKey(t.StartTagId))
                    {
                        startTag = tlvm.ChargeTags[t.StartTagId]?.TagName;
                    }
                    if (!string.IsNullOrEmpty(t.StopTagId) && tlvm.ChargeTags != null && tlvm.ChargeTags.ContainsKey(t.StopTagId))
                    {
                        stopTag = tlvm.ChargeTags[t.StopTagId]?.TagName;
                    }

                    csv.AppendLine();
                    csv.Append(EscapeCsvValue(tlvm.CurrentChargePointName));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(t.ConnectorId.ToString()));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(t.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(startTag));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(t.MeterStart.ToString()));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(((t.StopTime != null) ? t.StopTime.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") : string.Empty)));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(stopTag));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(((t.MeterStop != null) ? t.MeterStop.ToString() : string.Empty)));
                    csv.Append(CSV_Seperator);
                    csv.Append(EscapeCsvValue(((t.MeterStop != null) ? (t.MeterStop - t.MeterStart).ToString() : string.Empty)));
                }
            }

            return(csv.ToString());
        }
Пример #2
0
        // GET: Transaction
        public async Task <IActionResult> Index(string id)
        {
            if (TempData?["Info"] != null)
            {
                ModelState.AddModelError(string.Empty, TempData["Info"].ToString());
            }
            var bankAccounts = await Utils.Get <List <BankAccount> >("api/bankaccount");

            var ownUserId = Guid.NewGuid();             //To pass unit test where User=null

            if (User != null)
            {
                ownUserId = new Guid(_userManager.GetUserId(User));
            }

            bankAccounts = bankAccounts.Where(o => o.OwnerId == ownUserId).ToList();
            if (bankAccounts.Any() && id == null)
            {
                id = bankAccounts[0].Id.ToString();
            }
            var selectList = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Välj kontonamn",
                    Value = ""
                }
            };

            selectList.AddRange(bankAccounts.Select(bankAcount => new SelectListItem
            {
                Text     = bankAcount.Comment,
                Value    = bankAcount.Id.ToString(),
                Selected = bankAcount.Id.ToString() == id
            }));
            var transactions = new List <Transaction>();

            if (id != null)
            {
                transactions = await Utils.Get <List <Transaction> >("api/transaction/");

                var bankAccountId = new Guid(id);
                transactions = transactions.Where(o => o.BankAccountId == bankAccountId).ToList();
            }

            var transactionListViewModel = new TransactionListViewModel
            {
                BankAccountSelectList = selectList,
                Transactions          = transactions
            };

            ViewBag.Saldo         = bankAccounts.SingleOrDefault(o => o.Id.ToString() == id)?.Balance;
            ViewBag.BankAccountId = id;
            return(View(transactionListViewModel));
        }
        // GET: Transaction
        public async Task <IActionResult> Index(string id)
        {
            var ownUserId = Guid.NewGuid(); //null Test to pass xUnit test where User=null

            if (User != null)
            {
                ownUserId = new Guid(_userManager.GetUserId(User));
            }
            var bankAccounts = await _context.BankAccount.Where(o => o.OwnerId == ownUserId).OrderBy(c => c.Comment).ToListAsync();

            if (bankAccounts.Any() && id == null)
            {
                id = bankAccounts[0].Id.ToString();
            }
            var selectList = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Välj kontonummer",
                    Value = ""
                }
            };

            foreach (var bankAcount in bankAccounts)
            {
                selectList.Add(new SelectListItem
                {
                    Text     = bankAcount.Comment,
                    Value    = bankAcount.Id.ToString(),
                    Selected = bankAcount.Id.ToString() == id
                });
            }
            var transactions = new List <Transaction>();

            if (id != null)
            {
                var bankAccount = await _context.BankAccount.SingleOrDefaultAsync(o => o.Id.ToString() == id);

                transactions = await _context.Transaction.Where(o => o.BankAccountId == bankAccount.Id).ToListAsync();
            }


            var transactionListViewModel = new TransactionListViewModel
            {
                BankAccounts = selectList,
                Transactions = transactions
            };

            ViewBag.BankAccountId = id;
            ViewBag.Saldo         = bankAccounts.SingleOrDefault(o => o.Id.ToString() == id)?.Balance;
            return(View(transactionListViewModel));
        }
        public async Task <IActionResult> ListTransactions(string accountId)
        {
            var result = await((BeBelfiusConnector)Storage.Connector).GetTransactionsAsync(accountId);
            TransactionListViewModel model = new TransactionListViewModel();

            model.AccountId = accountId;
            if (result.GetStatus() == ResultStatus.DONE)
            {
                model.Transactions = result.GetData();
            }

            return(View(model));
        }
Пример #5
0
        public TransactionListPage(Account account)
        {
            this.account = account;
            viewModel    = new TransactionListViewModel(account);

            viewModel.OnError += ViewModel_OnError;
            viewModel.OnInitializationError += ViewModel_OnInitializationError;

            BindingContext = viewModel;

            Title = account.Name;
            InitializeComponent();
        }
        public ActionResult HouseholdTransactions(int?Id)
        {
            if (Id is null)
            {
                TempData.Add("Message", "Improper Id");
                TempData.Add("MessageColour", "danger");
                return(RedirectToAction("Index", "Household"));
            }

            var url = $"{ProjectConstants.APIURL}/api/transaction/getallbyhousehold/{Id}";

            var token      = Request.Cookies["UserAuthCookie"].Value;
            var authHeader = new AuthenticationHeaderValue("Bearer", token);

            HttpClientContext.httpClient.DefaultRequestHeaders.Authorization = authHeader;

            // Handling lack of connection??? try catch?
            var response = HttpClientContext.httpClient.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseResult = response.Content.ReadAsStringAsync().Result;

                var datas = JsonConvert.DeserializeObject <List <TransactionViewModel> >(responseResult);

                foreach (var item in datas)
                {
                    item.CategoryName    = HouseholdHelpers.GetCategoryName(item.CategoryId, Request);
                    item.BankAccountName = HouseholdHelpers.GetBankAccountName(item.BankAccountId, Request);
                    item.UserCanEdit     = TransactionHelpers.IsUserCreator(item.Id, Request, TempData);
                }

                var viewModel = new TransactionListViewModel
                {
                    Transactions             = datas,
                    HouseholdId              = (int)Id,
                    IsHouseholdOwnerOrMember = HouseholdHelpers.IsUserCreatorOrMember((int)Id, Request, TempData)
                };
                return(View(viewModel));
            }
            else
            {
                ErrorHelpers.HandleResponseErrors(response, TempData, ModelState);
                return(RedirectToAction("Index", "Household"));
            }
        }
Пример #7
0
        public async Task <IActionResult> Index(int year = 0, int month = 0)
        {
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }
            if (month == 0)
            {
                month = DateTime.Now.Month;
            }
            var transactions = await _transactionService.GetTransactionByMonthAndYear(month, year);

            var viewModel = new TransactionListViewModel();

            viewModel.Transactions  = transactions;
            viewModel.TotalIncome   = _transactionService.GetTotalAmount(true, transactions);
            viewModel.TotalExpenses = _transactionService.GetTotalAmount(false, transactions);

            ViewBag.Date = month + "/" + year;
            return(View("Index", viewModel));
        }
Пример #8
0
        public InventoryModule()
        {
            ListInventoryItemsCommand = new CategoryCommand<string>(Resources.InventoryItems, Resources.Products, OnListInventoryItems) { Order = 26 };
            ListRecipesCommand = new CategoryCommand<string>(Resources.Recipes, Resources.Products, OnListRecipes) { Order = 27 };
            ListTransactionsCommand = new CategoryCommand<string>(Resources.Transactions, Resources.Products, OnListTransactions) { Order = 28 };
            ListPeriodicConsumptionsCommand = new CategoryCommand<string>(Resources.EndOfDayRecords, Resources.Products, OnListPeriodicConsumptions) { Order = 29 };

            EventServiceFactory.EventService.GetEvent<GenericEvent<VisibleViewModelBase>>().Subscribe(s =>
            {
                if (s.Topic == EventTopicNames.ViewClosed)
                {
                    if (s.Value == _inventoryItemListViewModel)
                        _inventoryItemListViewModel = null;
                    if (s.Value == _recipeListViewModel)
                        _recipeListViewModel = null;
                    if (s.Value == _transactionListViewModel)
                        _transactionListViewModel = null;
                    if (s.Value == _periodicConsumptionListViewModel)
                        _periodicConsumptionListViewModel = null;
                }
            });

            EventServiceFactory.EventService.GetEvent<GenericEvent<WorkPeriod>>().Subscribe(OnWorkperiodStatusChanged);
        }
 public void AddToTransactionsList(TransactionListViewModel tx)
 {
     this.transactions.Add(tx);
     this.EnsureTransactionsList();
 }
Пример #10
0
 private void OnListTransactions(string obj)
 {
     if (_transactionListViewModel == null)
         _transactionListViewModel = new TransactionListViewModel();
     CommonEventPublisher.PublishViewAddedEvent(_transactionListViewModel);
 }
        public TransactionListViewModel GetListTransaction(entity.Enums.TransactionStatus?status = null, int?month = null, int?year = null, int?categoryId = null)
        {
            var transactions = transactionRepository.Gets();

            if (status != null)
            {
                if (status != entity.Enums.TransactionStatus.Delivered)
                {
                    transactions = transactions.Where(t => t.StatusID == (int)status && t.Delivered == false);
                }
                else
                {
                    transactions = transactions.Where(t => t.Delivered == true);
                }
            }
            if (month != null && year != null)
            {
                transactions = transactions.Where(t => t.RecievedDate.Value.Month == month && t.RecievedDate.Value.Year == year);
            }
            else
            {
                transactions = transactions.Where(t => t.RecievedDate.Value.Month == DateTime.Now.Month && t.RecievedDate.Value.Year == DateTime.Now.Year);
            }
            if (categoryId != null)
            {
                transactions = transactions.Where(t => t.TypeID == categoryId);
            }

            var result = new TransactionListViewModel
            {
                Status       = status,
                Transactions = transactions.Select(t => new TransactionViewModel()
                {
                    TransactionID = t.TransactionID,
                    DeliveredDate = t.DeliverDate,
                    Description   = t.Description,
                    Error         = t.Error,
                    Price         = t.Price,
                    Reason        = t.Reason,
                    Delivered     = t.Delivered,
                    RecievedDate  = t.RecievedDate,
                    Status        = (entity.Enums.TransactionStatus)t.StatusID,
                    Category      = new CategoryViewModel
                    {
                        CategoryID = t.Category.CategoryID,
                        Name       = t.Category.Name
                    },
                    Customer = new CustomerViewModel
                    {
                        CustomerID = t.Customer.CustomerID,
                        Name       = t.Customer.Name,
                        Phone      = t.Customer.Phone
                    },
                    ListPriceDetail = t.DetailPrices.Select(p => new PriceDetailViewModel()
                    {
                        TransactionID = p.TransactionID.Value,
                        Description   = p.Description,
                        Price         = p.Price.Value
                    })
                })
            };

            return(result);
        }
Пример #12
0
        public IActionResult Transactions(string Id)
        {
            Logger.LogTrace("Transactions: Loading charge point transactions...");

            TransactionListViewModel tlvm = new TransactionListViewModel();

            tlvm.CurrentChargePointId = Id;
            tlvm.ChargePoints         = new List <ChargePoint>();
            tlvm.Transactions         = new List <Transaction>();

            try
            {
                string ts   = Request.Query["t"];
                int    days = 30;
                if (ts == "2")
                {
                    // 90 days
                    days          = 90;
                    tlvm.Timespan = 2;
                }
                else if (ts == "3")
                {
                    // 365 days
                    days          = 365;
                    tlvm.Timespan = 3;
                }
                else
                {
                    // 30 days
                    days          = 30;
                    tlvm.Timespan = 1;
                }

                using (OCPPCoreContext dbContext = new OCPPCoreContext(this.Config))
                {
                    Logger.LogTrace("Transactions: Loading charge points...");
                    tlvm.ChargePoints = dbContext.ChargePoints.ToList <ChargePoint>();
                    // search selected charge point
                    foreach (ChargePoint cp in tlvm.ChargePoints)
                    {
                        if (cp.ChargePointId == Id)
                        {
                            tlvm.CurrentChargePointName = cp.Name;
                            if (string.IsNullOrEmpty(tlvm.CurrentChargePointName))
                            {
                                tlvm.CurrentChargePointName = Id;
                            }
                            break;
                        }
                    }

                    // load charge tags for name resolution
                    Logger.LogTrace("Transactions: Loading charge tags...");
                    List <ChargeTag> chargeTags = dbContext.ChargeTags.ToList <ChargeTag>();
                    tlvm.ChargeTags = new Dictionary <string, ChargeTag>();
                    if (chargeTags != null)
                    {
                        foreach (ChargeTag tag in chargeTags)
                        {
                            tlvm.ChargeTags.Add(tag.TagId, tag);
                        }
                    }

                    if (!string.IsNullOrEmpty(tlvm.CurrentChargePointId))
                    {
                        Logger.LogTrace("Transactions: Loading charge point transactions...");
                        tlvm.Transactions = dbContext.Transactions
                                            .Where(t => t.ChargePointId == tlvm.CurrentChargePointId && t.StartTime >= DateTime.UtcNow.AddDays(-1 * days))
                                            .OrderByDescending(t => t.TransactionId)
                                            .ToList <Transaction>();
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.LogError(exp, "Transactions: Error loading charge points from database");
            }

            return(View(tlvm));
        }
Пример #13
0
        public IActionResult Export(string Id)
        {
            Logger.LogTrace("Export: Loading charge point transactions...");

            TransactionListViewModel tlvm = new TransactionListViewModel();

            tlvm.CurrentChargePointId = Id;
            tlvm.ChargePoints         = new List <ChargePoint>();
            tlvm.Transactions         = new List <Transaction>();

            try
            {
                string ts   = Request.Query["t"];
                int    days = 30;
                if (ts == "2")
                {
                    // 90 days
                    days          = 90;
                    tlvm.Timespan = 2;
                }
                else if (ts == "3")
                {
                    // 365 days
                    days          = 365;
                    tlvm.Timespan = 3;
                }
                else
                {
                    // 30 days
                    days          = 30;
                    tlvm.Timespan = 1;
                }

                using (OCPPCoreContext dbContext = new OCPPCoreContext(this.Config))
                {
                    Logger.LogTrace("Export: Loading charge points...");
                    tlvm.ChargePoints = dbContext.ChargePoints.ToList <ChargePoint>();

                    foreach (ChargePoint cp in tlvm.ChargePoints)
                    {
                        if (cp.ChargePointId == Id)
                        {
                            tlvm.CurrentChargePointName = cp.Name;
                            if (string.IsNullOrEmpty(tlvm.CurrentChargePointName))
                            {
                                tlvm.CurrentChargePointName = Id;
                            }
                            break;
                        }
                    }

                    // load charge tags for name resolution
                    Logger.LogTrace("Export: Loading charge tags...");
                    tlvm.ChargePoints = dbContext.ChargePoints.ToList <ChargePoint>();
                    List <ChargeTag> chargeTags = dbContext.ChargeTags.ToList <ChargeTag>();
                    tlvm.ChargeTags = new Dictionary <string, ChargeTag>();
                    if (chargeTags != null)
                    {
                        foreach (ChargeTag tag in chargeTags)
                        {
                            tlvm.ChargeTags.Add(tag.TagId, tag);
                        }
                    }

                    if (!string.IsNullOrEmpty(tlvm.CurrentChargePointId))
                    {
                        Logger.LogTrace("Export: Loading charge point transactions...");
                        tlvm.Transactions = dbContext.Transactions
                                            .Where(t => t.ChargePointId == tlvm.CurrentChargePointId && t.StartTime >= DateTime.UtcNow.AddDays(-1 * days))
                                            .OrderByDescending(t => t.TransactionId)
                                            .ToList <Transaction>();
                    }

                    StringBuilder chargepointName = new StringBuilder(tlvm.CurrentChargePointName);
                    foreach (char c in Path.GetInvalidFileNameChars())
                    {
                        chargepointName.Replace(c, '_');
                    }

                    string filename = string.Format("Transactions_{0}.csv", chargepointName);
                    string csv      = CreateCsv(tlvm);
                    Logger.LogInformation("Export: File => {0} Chars / Name '{1}'", csv.Length, filename);

                    return(File(Encoding.GetEncoding("ISO-8859-1").GetBytes(csv), "text/csv", filename));
                }
            }
            catch (Exception exp)
            {
                Logger.LogError(exp, "Export: Error loading charge points from database");
            }

            return(View(tlvm));
        }