Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.InvestmentTransaction


    }

    @RequestMapping("/view/{id}")
    public String view(@PathVariable Long id, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      InvestmentTransaction transaction = InvestmentTransaction.findInvestmentTransaction(id);
      Account account = transaction.getAccountTransaction().getAccount();
      if (account.belongsTo(user)) {
        modelMap.addAttribute("account", account);
        modelMap.addAttribute("transaction", transaction);
        modelMap.addAttribute("investments", Investment.findInvestmentsByOwner(user));
      }
View Full Code Here


    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String edit(InvestmentTransaction transaction, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      InvestmentTransaction loaded = InvestmentTransaction.findInvestmentTransaction(transaction.getId());
      Account account = loaded.getAccountTransaction().getAccount();
      if (account.belongsTo(user)) {
        cache.invalidate(user);
        AccountTransaction accountTransaction = loaded.getAccountTransaction();
        if (transaction.getPrice() != null) {
          loaded.setQuantity(transaction.getQuantity());
          loaded.getPrice().setPrice(transaction.getPrice().getPrice());
          accountTransaction.setAmount(new BigDecimal(transaction.getQuantity() * transaction.getPrice().getPrice()));
        } else {
          loaded.setPrice(null);
          accountTransaction.setAmount(transaction.getAccountTransaction().getAmount());
        }
        Investment investment = Investment.findInvestment(transaction.getInvestment().getId());
        loaded.setInvestment(investment);
        loaded.getAccountTransaction().setPayee(investment)
        accountTransaction.setOperationDate(transaction.getAccountTransaction().getOperationDate());
        accountTransaction.setReferenceNumber(transaction.getAccountTransaction().getReferenceNumber());
        accountTransaction.setSubcategory(Subcategory.findBySubcategory(transaction.getAccountTransaction().getSubcategory().getCategory(), user));
        loaded.merge();
      }
      return "redirect:/financial/accounts/" + account.getId();
    }
View Full Code Here

    @RequestMapping("/remove/{id}")
    public String remove(@PathVariable Long id, ModelMap modelMap) {
      Long accountId = null;
      UserDetails user = UserDetails.findCurrentUser();
      InvestmentTransaction transaction  = InvestmentTransaction.findInvestmentTransaction(id);
      if (transaction != null) {
        AccountTransaction accountTransaction = transaction.getAccountTransaction();
        Account account = accountTransaction.getAccount();
        if (account.belongsTo(user)) {
          cache.invalidate(user);
          accountId = account.getId();
          accountTransaction.remove();
View Full Code Here

    investment.setSymbol("INV");
    investment.setName("investment");
    investment.setProductType("type");
    investment.setOwner(account.getOwner());
    investment.persist();
    InvestmentTransaction transaction = new InvestmentTransaction();
    transaction.setQuantity(5D);
    transaction.setInvestment(new Investment());
    transaction.getInvestment().setId(investment.getId());
    transaction.setPrice(new InvestmentPrice());
    transaction.getPrice().setPrice(2D);
    transaction.setAccountTransaction(new AccountTransaction());
    transaction.getAccountTransaction().setAccount(new Account());
    transaction.getAccountTransaction().getAccount().setId(1L);
    transaction.getAccountTransaction().setAmount(BigDecimal.TEN);
    transaction.getAccountTransaction().setOperationDate(DateUtils.getMidnight(new Date()));
    transaction.getAccountTransaction().setSubcategory(new Subcategory());
    transaction.getAccountTransaction().getSubcategory().setCategory("category.investment.buy");
    double balance = account.calculateBalance().doubleValue();
    investmentService.addInvestment(account.getOwner(), account, transaction, 11D);
    assertNotNull("Transaction persisted", transaction.getId());
    assertNotNull("Investment price persisted", transaction.getPrice().getId());
    assertNotNull("Account transaction persisted", transaction.getAccountTransaction().getId());
    assertEquals("One price available for the investment", new Double(2D), investment.getCurrentPrice());
    assertEquals("Balance was updated accordingly", new Double(balance - 21D), new Double(account.calculateBalance().doubleValue()));
  }
View Full Code Here

        transaction.setSubcategory(getOrCreateSubcategory(account.getOwner(), register));
      } else if (register.isInvestment()) {
        transaction.setReconciled(Boolean.FALSE);
        Investment investment = getOrCreateInvestment(register, account);
        transaction.setPayee(investment);
        InvestmentTransaction investmentTransaction = new InvestmentTransaction();
        investment.addInvestment(investmentTransaction);
        investmentTransaction.setAccountTransaction(transaction);
        if (register.getPrice() != null) {
          investmentTransaction.setPrice(new InvestmentPrice());
          investmentTransaction.getPrice().setInvestment(investment);
          investmentTransaction.getPrice().setPrice(register.getPrice());
          investmentTransaction.getPrice().setUpdateTime(transaction.getOperationDate());
          investmentTransaction.setQuantity(register.getQuantity());
        } else {
          investmentTransaction.setPrice(null);
          investmentTransaction.setQuantity(new Double(0D));
        }
        transaction.setInvestment(investmentTransaction);
        String subcat = Register.Operation.BUY.equals(register.getOperation()) ? "category.investment.buy" : Register.Operation.SELL.equals(register.getOperation()) ? "category.investment.sell" : "category.investment.interest";
        if (Register.Operation.BUY.equals(register.getOperation())) {
          transaction.setAmount(transaction.getAmount().negate());
View Full Code Here

    InvestmentPrice price = new InvestmentPrice();
    price.setPrice(1D);
    price.setInvestment(investment);
    price.setUpdateTime(DateUtils.getMidnight(new Date()));
    price.persist();
    InvestmentTransaction investmentTransaction = new InvestmentTransaction();
    investmentTransaction.setId(14L);
    investmentTransaction.setPrice(price);
    investmentTransaction.setQuantity(10D);
    investmentTransaction.setInvestment(investment);
    investmentTransaction.setAccountTransaction(transaction);
    transaction.setInvestment(investmentTransaction);
    InvestmentStatus investmentStatus = new InvestmentStatus(account, investment);
    investmentStatus.add(transaction);
    assertEquals("JSON", "{operationDate:'', id: 5, label: 'Investment', buy: '10,00 €', sell: '', interest: '', gainLoss: '', pctg: '0%', quantity: '10', price: '1,00 €', operations: [{id: 999914, label: '', buy: '10,00 €', sell: '', interest: '', quantity: '10', price: '1,00 €', gainLoss: '', pctg: '', quant: 10.0, operationDate: '2000-11-20'}], quant: 10.0}", investmentStatus.getAsJSONString());
    AccountTransaction sellTransaction = new AccountTransaction();
    sellTransaction.setAccount(account);
    Subcategory sellSubcategory = Subcategory.findBySubcategory("category.investment.sell", account.getOwner());
    sellTransaction.setSubcategory(sellSubcategory);
    sellTransaction.setAmount(new BigDecimal(1.5));
    InvestmentPrice updatedPrice = new InvestmentPrice();
    updatedPrice.setPrice(1.5D);
    updatedPrice.setUpdateTime(DateUtils.nextDate(DateUtils.getMidnight(new Date())));
    updatedPrice.setInvestment(investment);
    updatedPrice.persist();
    InvestmentTransaction investmentSellTransaction = new InvestmentTransaction();
    investmentSellTransaction.setId(15L);
    investmentSellTransaction.setQuantity(1D);
    investmentSellTransaction.setPrice(updatedPrice);
    investmentSellTransaction.setInvestment(investment);
    investmentSellTransaction.setAccountTransaction(sellTransaction);
    sellTransaction.setInvestment(investmentSellTransaction);
    sellTransaction.setOperationDate(new Date(100, 10, 21));
    investmentStatus.add(sellTransaction);
    assertEquals("JSON (buy & sell)", "{operationDate:'', id: 5, label: 'Investment', buy: '10,00 €', sell: '1,50 €', interest: '', gainLoss: '5,00 €', pctg: '50%', quantity: '9', price: '1,50 €', operations: [{id: 999914, label: '', buy: '10,00 €', sell: '', interest: '', quantity: '10', price: '1,00 €', gainLoss: '', pctg: '', quant: 10.0, operationDate: '2000-11-20'},{id: 999915, label: '', buy: '', sell: '1,50 €', interest: '', quantity: '1', price: '1,50 €', gainLoss: '', pctg: '', quant: 1.0, operationDate: '2000-11-21'}], quant: 9.0}", investmentStatus.getAsJSONString());
    Investment amountedInvestment = new Investment();
    amountedInvestment.setName("Investment (amount)");
    amountedInvestment.setOwner(account.getOwner());
    amountedInvestment.setProductType("deposit");
    amountedInvestment.persist();
    InvestmentStatus amountedInvestmentStatus = new InvestmentStatus(account, amountedInvestment);
    InvestmentTransaction amountedInvestmentTransaction = new InvestmentTransaction();
    amountedInvestmentTransaction.setId(26L);
    amountedInvestmentTransaction.setQuantity(0D);
    amountedInvestmentTransaction.setInvestment(amountedInvestment);
    AccountTransaction amountedTransaction = new AccountTransaction();
    amountedTransaction.setAccount(account);
    amountedTransaction.setSubcategory(subcategory);
    amountedTransaction.setAmount(BigDecimal.TEN.negate());
    amountedTransaction.setOperationDate(new Date(100, 10, 22));
    amountedInvestmentTransaction.setAccountTransaction(amountedTransaction);
    amountedTransaction.setInvestment(amountedInvestmentTransaction);
    amountedInvestmentStatus.add(amountedTransaction);
    assertEquals("No quantity, no gain/loss", "{operationDate:'', id: 6, label: 'Investment (amount)', buy: '10,00 €', sell: '', interest: '', gainLoss: '', pctg: '0%', quantity: '', price: '', operations: [{id: 999926, label: '', buy: '10,00 €', sell: '', interest: '', quantity: '', price: '', gainLoss: '', pctg: '', quant: 0.0, operationDate: '2000-11-22'}], quant: 0.0}", amountedInvestmentStatus.getAsJSONString());
    InvestmentTransaction amountedInvestmentInterestTransaction = new InvestmentTransaction();
    amountedInvestmentInterestTransaction.setId(29L);
    amountedInvestmentInterestTransaction.setQuantity(0D);
    amountedInvestmentInterestTransaction.setInvestment(amountedInvestment);
    AccountTransaction amountedInterestTransaction = new AccountTransaction();
    amountedInterestTransaction.setAccount(account);
    amountedInterestTransaction.setOperationDate(new Date(100, 10, 23));
    Subcategory interest = Subcategory.findBySubcategory("category.investment.interest", account.getOwner());
    amountedInterestTransaction.setSubcategory(interest);
    amountedInterestTransaction.setAmount(BigDecimal.TEN);
    amountedInvestmentInterestTransaction.setAccountTransaction(amountedInterestTransaction);
    amountedInterestTransaction.setInvestment(amountedInvestmentInterestTransaction);
    amountedInvestmentStatus.add(amountedInterestTransaction);
    assertEquals("Interest gain/loss", "{operationDate:'', id: 6, label: 'Investment (amount)', buy: '10,00 €', sell: '', interest: '10,00 €', gainLoss: '10,00 €', pctg: '100%', quantity: '', price: '', operations: [{id: 999926, label: '', buy: '10,00 €', sell: '', interest: '', quantity: '', price: '', gainLoss: '', pctg: '', quant: 0.0, operationDate: '2000-11-22'},{id: 999929, label: '', buy: '', sell: '', interest: '10,00 €', quantity: '', price: '', gainLoss: '', pctg: '', quant: 0.0, operationDate: '2000-11-23'}], quant: 0.0}", amountedInvestmentStatus.getAsJSONString());
  }
View Full Code Here

TOP

Related Classes of org.internna.ossmoney.model.InvestmentTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.