Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.Investment


    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public String create(String type, String name, String symbol, String locale, ModelMap modelMap) {
      String[] parts = locale.split("_");
        Investment investment = new Investment();
        investment.setName(name);
        investment.setSymbol(symbol);
        investment.setProductType(type);
        investment.setOwner(UserDetails.findCurrentUser());
        investment.setLocale(new Locale(parts[0], parts[1], ""));
        investment.persist();
        return "redirect:/financial/accounts";
    }
View Full Code Here


          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));
View Full Code Here

    @RequestMapping("/prices/{id}")
    public String getPrices(@PathVariable Long id, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      String currency = "EUR";
      Investment investment = Investment.findInvestment(id);
      Set<InvestmentPrice> prices = new TreeSet<InvestmentPrice>();
      Set<InvestmentPrice> datedPrices = new TreeSet<InvestmentPrice>();
      if (investment.belongsTo(user)) {
        if (investment.getLocale() != null) {
          Locale locale = investment.getLocale();
          Currency investmentCurrency = Currency.getInstance(locale);
          currency = investmentCurrency.getCurrencyCode();
        }
        modelMap.addAttribute("investment", investment.getName());
        prices.addAll(InvestmentPrice.findInvestmentPricesByInvestment(investment));
        datedPrices.addAll(prices);
        fill(datedPrices);
      }
      modelMap.addAttribute("id", id);
View Full Code Here

    }

    @RequestMapping(value = "/prices", method = RequestMethod.POST)
    public String setPrice(Long investmentId, Long priceId, Date operationDate, Double amount, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      Investment investment = Investment.findInvestment(investmentId);
      InvestmentPrice price = InvestmentPrice.findInvestmentPrice(priceId);
      if (price == null) {
        price = new InvestmentPrice();
        investment.addPrice(price);
      }
      if ((investment != null) && investment.belongsTo(user) && price.belongsTo(investment)) {
        price.setPrice(amount);
        price.setUpdateTime(operationDate);
        if (price.getId() != null) {
          price.merge();
        } else {
View Full Code Here

public class InvestmentService implements org.internna.ossmoney.services.InvestmentService {

  @Override public void addInvestment(UserDetails user, Account account, InvestmentTransaction transaction, double commision) {
    String subcat = transaction.getAccountTransaction().getSubcategory().getCategory();
    Subcategory subcategory = Subcategory.findBySubcategory(subcat, user);
    Investment investment = Investment.findInvestment(transaction.getInvestment().getId());
    investment.addInvestment(transaction);
    BigDecimal amount = transaction.getAccountTransaction().getAmount();
    if ((amount == null) || BigDecimal.ZERO.equals(amount)) {
      amount = new BigDecimal(transaction.getQuantity() * transaction.getPrice().getPrice());
    } else {
      transaction.setQuantity(0D);
View Full Code Here

    register.setQuantity(100.0);
    register.setInvestment("investment");
    register.setOperation(Operation.BUY);
    qifImporterService.process(register, account);
    assertEquals("Investment transaction saved", number + 2, account.getTransactions().size());
    Investment investment = Investment.findByName("investment", account.getOwner());
    assertNotNull("Investment created", investment);
    assertEquals("One transaction", new Integer(1), new Integer(investment.getInvestments().size()));
    assertEquals("Correct price", new Double(98.34), investment.getInvestments().iterator().next().getPrice().getPrice());
  }
View Full Code Here

    SecurityUtils.authenticate(authenticationManager, "jose", "jose");
  }

  @Test
  public void testAddInvestment() {
    Investment investment = new Investment();
    Account account = Account.findAccount(1L);
    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.setReconciled(register.getReconciled());
        transaction.setPayee(getOrCreatePayee(register, account));
        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());
View Full Code Here

    }
    return payee;
  }

  protected Investment getOrCreateInvestment(Register register, Account account) {
    Investment investment = Investment.findByName(register.getInvestment(), account.getOwner());
    if (investment == null) {
      investment = new Investment();
      investment.setOwner(account.getOwner());
      investment.setName(register.getInvestment());
      investment.setProductType("investment.unknown");
      investment.persist();
      investment.flush();
    }
    return investment;
  }
View Full Code Here

    transaction.setAccount(account);
    Subcategory subcategory = Subcategory.findBySubcategory("category.investment.buy", account.getOwner());
    transaction.setSubcategory(subcategory);
    transaction.setAmount(BigDecimal.TEN.negate());
    transaction.setOperationDate(new Date(100, 10, 20));
    Investment investment = new Investment();
    investment.setName("Investment");
    investment.setProductType("stocks");
    investment.setOwner(account.getOwner());
    investment.persist();
    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);
View Full Code Here

TOP

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

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.