コード例 #1
0
ファイル: CashService.cs プロジェクト: yurseli/sambapos
        private static void AddTransaction(int customerId, decimal amount, string description, PaymentType paymentType, TransactionType transactionType)
        {
            using (var workspace = WorkspaceFactory.Create())
            {
                if (transactionType == TransactionType.Income || transactionType == TransactionType.Expense)
                {
                    var c = new CashTransaction
                    {
                        Amount          = amount,
                        Date            = DateTime.Now,
                        Name            = description,
                        PaymentType     = (int)paymentType,
                        TransactionType = (int)transactionType,
                        UserId          = AppServices.CurrentLoggedInUser.Id,
                        CustomerId      = customerId
                    };
                    workspace.Add(c);
                }
                else
                {
                    var c = new AccountTransaction
                    {
                        Amount          = amount,
                        Date            = DateTime.Now,
                        Name            = description,
                        TransactionType = (int)transactionType,
                        UserId          = AppServices.CurrentLoggedInUser.Id,
                        CustomerId      = customerId
                    };
                    workspace.Add(c);
                }

                workspace.CommitChanges();
            }
        }
コード例 #2
0
        private async Task AskAndDelete(CashTransaction record)
        {
            if (record == null)
            {
                ShowMessage("Сначала выделите запись!");
                return;
            }

            var w      = (MetroWindow)Parent.GetParentObject().GetParentObject();
            var result = await w.ShowMessageAsync("Удалить запись?",
                                                  string.Format("Дата: {1:dd MMMM yyyy}{0}Сумма: {2:C}{0}Комментарий: {3}{0}Сотрудник: {4}",
                                                                Environment.NewLine, record.Date, record.Sum, record.Comment, record.EmployeeFullName),
                                                  MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                const string deleteTransactionSql = "delete from ba_cash_operations where id = @id;";
                if (App.Sqlite.Delete(deleteTransactionSql, new XParameter("@id", record.Id)) <= (int)XQuery.XResult.NothingChanged)
                {
                    ShowMessage("Не удалось удалить запись из базы данных!");
                    return;
                }
                LoadHistory();
            }
        }
コード例 #3
0
        public void MakeCashTransaction()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stockResolver = mockRepository.Create <IStockResolver>();

            var             handler     = mockRepository.Create <ITransactionHandler>();
            CashTransaction transaction = null;

            handler.Setup(x => x.Apply(It.IsAny <IPortfolioTransaction>(), It.IsAny <IHolding>(), It.IsAny <ICashAccount>()))
            .Callback <IPortfolioTransaction, IHolding, ICashAccount>((t, h, c) => transaction = (CashTransaction)t)
            .Verifiable();

            var transactionHandlers = mockRepository.Create <IServiceFactory <ITransactionHandler> >();

            transactionHandlers.Setup(x => x.GetService <CashTransaction>()).Returns(handler.Object);

            var portfolio = new Portfolio(Guid.NewGuid(), stockResolver.Object, transactionHandlers.Object);

            var transactionId = Guid.NewGuid();

            portfolio.MakeCashTransaction(new Date(2000, 01, 01), BankAccountTransactionType.Transfer, 100.00m, "Comment", transactionId);

            transaction.Should().BeEquivalentTo(new
            {
                Id                  = transaction.Id,
                Date                = new Date(2000, 01, 01),
                Comment             = "Comment",
                CashTransactionType = BankAccountTransactionType.Transfer,
                Amount              = 100.00m
            });

            mockRepository.Verify();
        }
コード例 #4
0
ファイル: TradesRepository.cs プロジェクト: mpvyard/QPAS
        public async Task AddCashTransaction(Trade trade, CashTransaction ct)
        {
            if (trade == null)
            {
                throw new ArgumentNullException(nameof(trade));
            }
            if (ct == null)
            {
                throw new ArgumentNullException(nameof(ct));
            }

            var oldTrade = ct.Trade;

            if (oldTrade != null && trade.ID == oldTrade.ID)
            {
                //no change
                return;
            }

            //remove the ct from its current trade
            await RemoveCashTransaction(oldTrade, ct).ConfigureAwait(true);

            //and then add it to the new one
            if (trade.CashTransactions == null)
            {
                trade.CashTransactions = new List <CashTransaction>();
            }

            trade.CashTransactions.Add(ct);
            ct.Trade   = trade;
            ct.TradeID = trade.ID;

            //finally update the stats of the new trade
            await UpdateStats(ct.Trade).ConfigureAwait(true);
        }
コード例 #5
0
        public ActionResult Select(int id)
        {
            var count  = _context.CashTransactions.Count();
            var cashId = Convert.ToString(DateTime.Today.Year) + "00" + Convert.ToString(count + 1) + Convert.ToString(DateTime.Today.Day);

            var cashTransaction = new CashTransaction();

            double totalPrice = 0;

            foreach (var c in _context.TempCarts.ToList())
            {
                totalPrice = totalPrice + (c.ProductPrice * c.Quantity);
            }


            var selectCustomer = _context.Customers.SingleOrDefault(c => c.Id == id);

            cashTransaction.Id                  = cashId;
            cashTransaction.CustomerId          = selectCustomer.Id;
            cashTransaction.CashTransactionDate = DateTime.Now;
            cashTransaction.OriginalTotalAmount = totalPrice;
            cashTransaction.Remarks             = "";
            _context.CashTransactions.Add(cashTransaction);
            _context.SaveChanges();
            return(RedirectToAction("CashTransactionSummary", new { cashId }));
        }
コード例 #6
0
        public void DeserializeCashTransaction()
        {
            var serializer = new RestClientSerializer();

            var transactionId = Guid.NewGuid();
            var stockId       = Guid.NewGuid();

            var json = "{\"id\":\"" + transactionId + "\","
                       + "\"stock\":\"" + stockId + "\","
                       + "\"type\":\"cashtransaction\","
                       + "\"transactionDate\":\"2000-01-10\","
                       + "\"comment\":\"comment\","
                       + "\"description\":\"description\","
                       + "\"cashTransactionType\":\"fee\","
                       + "\"amount\":15.00}";

            var transaction = serializer.Deserialize <Transaction>(json);

            var expected = new CashTransaction()
            {
                Id                  = transactionId,
                Stock               = stockId,
                TransactionDate     = new Date(2000, 01, 10),
                Comment             = "comment",
                Description         = "description",
                CashTransactionType = CashTransactionType.Fee,
                Amount              = 15.00m
            };

            transaction.Should().BeEquivalentTo(expected);
        }
コード例 #7
0
        public async Task <string> CashTransaction(CashTransaction cashTransaction)
        {
            CashTransactionDomainModel cashTransactionDM = new CashTransactionDomainModel();

            AutoMapper.Mapper.Map(cashTransaction, cashTransactionDM);
            return(await accountBusiness.CashTransaction(cashTransactionDM));
        }
コード例 #8
0
        public void ROACValueIsCorrectWithCashTransactions()
        {
            var pos = new Position(_instrument);
            var o   = new Order
            {
                Quantity     = 100,
                Price        = 10,
                Instrument   = _instrument,
                FXRateToBase = 1
            };

            pos.AddOrder(o);

            var c = new CashTransaction
            {
                Amount       = 10,
                Instrument   = _instrument,
                FXRateToBase = 1
            };

            pos.AddCashTransaction(c);

            pos.GetPnL(10, 1);

            Assert.AreEqual(1.01, pos.ROAC);
        }
コード例 #9
0
        public void PnLIsDeferredForROACCalculationsIfNoCapitalIsUsed()
        {
            var pos = new Position(_instrument);
            var c   = new CashTransaction
            {
                Amount       = 10,
                Instrument   = _instrument,
                FXRateToBase = 1
            };

            pos.AddCashTransaction(c);

            pos.GetPnL(10, 1);

            var o = new Order
            {
                Quantity     = 100,
                Price        = 10,
                Instrument   = _instrument,
                FXRateToBase = 1
            };

            pos.AddOrder(o);

            pos.GetPnL(10, 1);

            Assert.AreEqual(1 + (10d / (10 * 100)), pos.ROAC);
        }
コード例 #10
0
        public void AddCashTransaction(CashTransaction ct)
        {
            Open = true;

            if (ct.InstrumentID.HasValue)
            {
                if (Positions.ContainsKey(ct.Instrument.ID))
                {
                    Positions[ct.Instrument.ID].AddCashTransaction(ct);
                }
            }
            else
            {
                //InstrumentID is null. This happens frequently
                //as many cash transactions are not related to a particular instrument
                Positions[NullInstrumentId].AddCashTransaction(ct);
            }

            if (ct.CurrencyID > 1)
            {
                var ft = new FXTransaction
                {
                    FXCurrency   = ct.Currency,
                    FXCurrencyID = ct.CurrencyID,
                    Quantity     = ct.Amount,
                    Proceeds     = ct.Amount * ct.FXRateToBase,
                    Cost         = -ct.Amount * ct.FXRateToBase,
                    DateTime     = ct.TransactionDate
                };
                AddFXTransaction(ft);
            }

            _cashTransactionsRemaining--;
        }
コード例 #11
0
ファイル: TradeTrackerTest.cs プロジェクト: zino974/QPAS
        public void AddingCashTransactionInForeignCurrencyResultsInFxPositionAddition()
        {
            var trade = new Trade();
            var date  = new DateTime(2000, 1, 1);
            var eur   = new Currency {
                ID = 2, Name = "EUR"
            };
            var ct = new CashTransaction {
                InstrumentID = 1, Currency = eur, CurrencyID = 2, Amount = 50, FXRateToBase = 1.5m, Instrument = _inst, TransactionDate = date, AssetCategory = AssetClass.Stock
            };

            trade.CashTransactions = new List <CashTransaction> {
                ct
            };
            var tracker = new TradeTracker(trade, 1);

            foreach (CashTransaction c in trade.CashTransactions)
            {
                tracker.AddCashTransaction(c);
            }

            Assert.IsTrue(tracker.CurrencyPositions.ContainsKey(2));
            Assert.IsTrue(tracker.CurrencyPositions[2].Quantity == 50);
            Assert.IsTrue(tracker.CurrencyPositions[2].CostBasis == 1.5m);
        }
コード例 #12
0
        public async Task <IActionResult> Create(TicketRoutePointTransactionViewModel trptvm)
        {
            if (ModelState.IsValid)
            {
                CashTransaction cashTransaction = new CashTransaction {
                    PayTime   = trptvm.PaimentTime,
                    TotalCash = trptvm.TicketPrice,
                    DcaId     = _context.DayCashAmount.FirstOrDefault(dca => dca.WorkDate == DateTime.Now.Date).DcaId,
                };
                _context.Add(cashTransaction);
                await _context.SaveChangesAsync();

                Ticket ticket = new Ticket
                {
                    PassengerId = trptvm.PassengerId,
                    Seat        = trptvm.Seat,
                    CtId        = _context.CashTransaction.ToList().Last().CtId,
                    TripId      = trptvm.TripId,
                    RpId        = trptvm.RPId
                };
                _context.Add(ticket);

                Trip trip = _context.Trip.FirstOrDefault(t => t.TripId == trptvm.TripId);
                trip.PassangersCount += 1;
                _context.Update(trip);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PassengerId"] = new SelectList(_context.Passenger, "PassengerId", "PassengerName", trptvm.PassengerId);
            return(View());
        }
コード例 #13
0
        public bool AddCashTransaction(CashTransactionDTO baDTO)
        {
            var flag = true;

            try
            {
                using (var entities = new ManiMotorsEntities1())
                {
                    var bTran = new CashTransaction()
                    {
                        TransactionType = baDTO.TransactionType,
                        Amount          = baDTO.Amount,
                        Description     = baDTO.Description,
                        TransactionDate = baDTO.TransactionDate,
                        CreatedDate     = baDTO.CreatedDate,
                        Createdby       = baDTO.CreatedBy,
                        Modifiedby      = baDTO.ModifiedBy,
                        ModifiedDate    = baDTO.ModifiedDate,
                        Type            = baDTO.Type,
                        Status          = baDTO.Status
                    };
                    entities.CashTransactions.Add(bTran);
                    entities.SaveChanges();
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                flag = false;
                throw ex;
            }

            return(flag);
        }
コード例 #14
0
        public void AddCashTransaction(CashTransaction ct)
        {
            if (!ct.InstrumentID.HasValue)
            {
                return;
            }

            if (Positions.ContainsKey(ct.Instrument.ID))
            {
                Positions[ct.Instrument.ID].AddCashTransaction(ct);
            }

            if (ct.CurrencyID > 1)
            {
                var ft = new FXTransaction
                {
                    FXCurrency   = ct.Currency,
                    FXCurrencyID = ct.CurrencyID,
                    Quantity     = ct.Amount,
                    Proceeds     = ct.Amount * ct.FXRateToBase,
                    Cost         = -ct.Amount * ct.FXRateToBase,
                    DateTime     = ct.TransactionDate
                };
                AddFXTransaction(ft);
            }
        }
コード例 #15
0
        private static CashTransactionResponse CreateCashTransactionResponse(CashTransaction cashTransaction, string iban, string sender, string recipient)
        {
            var isTransferFees = cashTransaction.Type == CashTransactionType.CommissionFees;

            return(new CashTransactionResponse(cashTransaction.From,
                                               cashTransaction.To,
                                               cashTransaction.From != iban ? cashTransaction.Amount : -cashTransaction.Amount,
                                               sender,
                                               recipient,
                                               cashTransaction.PaymentType,
                                               isTransferFees ? "Transfer commission Fees" :
                                               cashTransaction.From != iban ?
                                               $"From: {sender}, Account No: {cashTransaction.From} "
                                                :
                                               cashTransaction.InitiatedBy == BankAssetType.POS ? cashTransaction.DebitCardNo != null ?
                                               $"{cashTransaction.InitiatedBy} purchase: card No: {cashTransaction.DebitCardNo}, {recipient}"
                                                :
                                               $"{cashTransaction.InitiatedBy} purchase: card No: {cashTransaction.CreditCardNo}, {recipient}"
                                                :
                                               $"{cashTransaction.To}--{recipient}, {cashTransaction.Description}",
                                               cashTransaction.InitiatedBy,
                                               cashTransaction.From != iban ? cashTransaction.RecipientRemainingBalance : cashTransaction.SenderRemainingBalance,
                                               cashTransaction.CreatedAt,
                                               cashTransaction.CreatedBy));
        }
コード例 #16
0
ファイル: TradesRepository.cs プロジェクト: zino974/QPAS
        public void AddCashTransaction(Trade trade, CashTransaction ct)
        {
            if (trade == null)
            {
                throw new ArgumentNullException("trade");
            }
            if (ct == null)
            {
                throw new ArgumentNullException("ct");
            }

            var oldTrade = ct.Trade;

            if (oldTrade != null && trade.ID == oldTrade.ID)
            {
                //no change
                return;
            }

            //remove the ct from its current trade
            RemoveCashTransaction(oldTrade, ct);

            //and then add it to the new one
            if (trade.CashTransactions == null)
            {
                trade.CashTransactions = new List <CashTransaction>();
            }

            trade.CashTransactions.Add(ct);
            ct.Trade   = trade;
            ct.TradeID = trade.ID;

            //finally update the stats of the new trade
            UpdateStats(ct.Trade);
        }
コード例 #17
0
        public async Task <CashTransaction> AddAsync(VirtualBankDbContext dbContext, CashTransaction transaction)
        {
            await dbContext.CashTransactions.AddAsync(transaction);

            await SaveAsync(dbContext);

            return(transaction);
        }
コード例 #18
0
        public async Task <CashTransaction> AddAsync(CashTransaction transaction)
        {
            await _dbContext.CashTransactions.AddAsync(transaction);

            await SaveAsync();

            return(transaction);
        }
コード例 #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            CashTransaction cashtransaction = db.CashTransactions.Find(id);

            db.CashTransactions.Remove(cashtransaction);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #20
0
        //
        // GET: /CashTransaction/Details/5

        public ActionResult Details(int id = 0)
        {
            CashTransaction cashtransaction = db.CashTransactions.Find(id);

            if (cashtransaction == null)
            {
                return(HttpNotFound());
            }
            return(View(cashtransaction));
        }
コード例 #21
0
        public void CreateBuyTransactions()
        {
            var portfolio = new Portfolio {
                Name = "Test Portfolio"
            };
            var account = new Account
            {
                Name        = "TD TFSA",
                Description = "TD TFSA Account CAD",
                Currency    = "CAD",
            };

            portfolio.Accounts.Add(account);
            this.model.Portfolios.Add(portfolio);
            this.model.SaveChanges();

            var           date     = DateTime.Now;
            const decimal Price    = (decimal)23.02;
            const decimal Quantity = (decimal)1000;
            const decimal Amount   = (Price * Quantity) + (decimal)9.99;

            var cashTransaction = new CashTransaction
            {
                TransactionDate = date,
                Description     = "Buying 1000 x $23.02 MSFT shares.",
                Comment         = "Great deal",
                Amount          = -Amount
            };

            var transaction = new AssetTransaction
            {
                TransactionDate = DateTime.Now,
                TickerSymbol    = "MSFT",
                Description     = "Microsoft Corporation",
                Price           = Price,
                Quantity        = Quantity,
                Commission      = (decimal)9.95,
                Amount          = Amount
            };

            account.CashTransactions.Add(cashTransaction);
            account.AssetTransactions.Add(transaction);

            this.model.SaveChanges();

            using (var vmodel = new IpmModel())
            {
                Assert.IsNotNull(vmodel);
                var pf = this.model.Portfolios.Find(portfolio.PortfolioId);
                Assert.IsNotNull(pf);
                var acc = pf.Accounts.FirstOrDefault(a => a.AccountId == account.AccountId);
                Assert.IsNotNull(acc);
                Assert.IsNotNull(acc.AssetTransactions.FirstOrDefault(t => t.TickerSymbol == "MSFT"));
            }
        }
コード例 #22
0
        //
        // GET: /CashTransaction/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CashTransaction cashtransaction = db.CashTransactions.Find(id);

            if (cashtransaction == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", cashtransaction.CustomerID);
            return(View(cashtransaction));
        }
コード例 #23
0
 public ActionResult Edit(CashTransaction cashtransaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cashtransaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", cashtransaction.CustomerID);
     return(View(cashtransaction));
 }
コード例 #24
0
ファイル: TradesRepository.cs プロジェクト: mpvyard/QPAS
 public async Task RemoveCashTransaction(Trade trade, CashTransaction ct)
 {
     if (trade == null || trade.CashTransactions == null || !trade.CashTransactions.Contains(ct))
     {
         return;
     }
     trade.CashTransactions.Remove(ct);
     ct.Trade   = null;
     ct.TradeID = null;
     await UpdateStats(trade).ConfigureAwait(true);
 }
コード例 #25
0
ファイル: TradesRepository.cs プロジェクト: zino974/QPAS
 public void RemoveCashTransaction(Trade trade, CashTransaction ct)
 {
     if (trade == null || trade.CashTransactions == null || !trade.CashTransactions.Contains(ct))
     {
         return;
     }
     trade.CashTransactions.Remove(ct);
     ct.Trade   = null;
     ct.TradeID = null;
     UpdateStats(trade);
 }
コード例 #26
0
        public async Task <CashTransaction> UpdateAsync(CashTransaction transaction)
        {
            var existingCashTransaction = await _dbContext.CashTransactions.Where(c => c.Id == transaction.Id && transaction.Disabled == false)
                                          .FirstOrDefaultAsync();

            if (existingCashTransaction != null)
            {
                _dbContext.Entry(existingCashTransaction).State = EntityState.Detached;
            }

            _dbContext.Entry(transaction).State = EntityState.Modified;
            await SaveAsync();

            return(transaction);
        }
コード例 #27
0
        public ActionResult Create(CashTransaction cashtransaction)
        {
            if (ModelState.IsValid)
            {
                var lastCashBalance = db.CashTransactions.Where(m => m.CustomerID == cashtransaction.CustomerID).OrderByDescending(m => m.CashTransactionID).FirstOrDefault().CashBalance;
                cashtransaction.CashBalance = (Convert.ToDecimal(cashtransaction.CashTransactionAmount) + Convert.ToDecimal(lastCashBalance)).ToString();
                cashtransaction.CreatedDate = DateTime.Now.ToString();
                db.CashTransactions.Add(cashtransaction);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", cashtransaction.CustomerID);
            return(View(cashtransaction));
        }
        protected override void CopyFieldsToTransaction()
        {
            if (_Transaction == null)
            {
                _Transaction = new CashTransaction();
            }

            base.CopyFieldsToTransaction();

            var cashTransaction = (CashTransaction)_Transaction;

            cashTransaction.TransactionDate     = RecordDate;
            cashTransaction.CashTransactionType = TransactionType;
            cashTransaction.Amount = Amount;
        }
コード例 #29
0
        public void MinimizeAmountsOfChange_WithOneHundredDollarsAndTwentyTwoCents_SetsChangeToOneHundredDollarsTwoDimesTwoPennies()
        {
            CashTransaction    ct  = new CashTransaction(0, 10022);
            SimpleCashRegister scr = new SimpleCashRegister();

            Dictionary <CashDenominations, int> expected = new Dictionary <CashDenominations, int>()
            {
                { CashDenominations.Dollars, 100 },
                { CashDenominations.Quarters, 0 },
                { CashDenominations.Dimes, 2 },
                { CashDenominations.Nickels, 0 },
                { CashDenominations.Pennies, 2 }
            };

            CollectionAssert.AreEqual(expected, scr.CalculateMinimumAmountsOfChange(ct));
        }
コード例 #30
0
        public void MinimizeAmountsOfChange_WithNinetyFourCents_SetsChangeToThreeQuartersOneDimeOneNickelFourPennies()
        {
            CashTransaction    ct  = new CashTransaction(0, 94);
            SimpleCashRegister scr = new SimpleCashRegister();

            Dictionary <CashDenominations, int> expected = new Dictionary <CashDenominations, int>()
            {
                { CashDenominations.Dollars, 0 },
                { CashDenominations.Quarters, 3 },
                { CashDenominations.Dimes, 1 },
                { CashDenominations.Nickels, 1 },
                { CashDenominations.Pennies, 4 }
            };

            CollectionAssert.AreEqual(expected, scr.CalculateMinimumAmountsOfChange(ct));
        }