Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.Account


    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String edit(Account account, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      Account loaded = Account.findAccount(account.getId());
      if (loaded.belongsTo(user)) {
        cache.invalidate(user);
      loaded.setIsbn(account.getIsbn());
        loaded.setName(account.getName());
        loaded.setLocale(account.getLocale());
        loaded.setOpened(account.getOpened());
        loaded.setFavorite(account.getFavorite());
        loaded.setDescription(account.getDescription());
        loaded.setAccountNumber(account.getAccountNumber());
        loaded.setInitialBalance(account.getInitialBalance());
        loaded.setHeldAt(FinancialInstitution.findFinancialInstitution(account.getHeldAt().getId()));
        loaded.merge();
      }
      return index(modelMap);
    }
View Full Code Here


      return details(loaded.getAccount().getId(), modelMap);
    }

    @RequestMapping("/remove/{id}")
    public String remove(@PathVariable Long id, ModelMap modelMap) {
      Account account = null;
      AccountTransaction transaction  = AccountTransaction.findAccountTransaction(id);
      if (transaction != null) {
        account = transaction.getAccount();
        if (account.belongsTo(UserDetails.findCurrentUser())) {
          transaction.remove();
        }
      }
      return details(account, modelMap);
    }
View Full Code Here

    }

    public final SortedSet<Account> getBankAccounts(final Locale locale) {
        return filter(new Predicate() {
            @Override public boolean evaluate(Object object) {
                Account account = (Account) object;
                return account.isBankAccount() && account.getLocale().equals(locale);
            }
        });
    }
View Full Code Here

  @Override public List<Message> importQIF(Locale locale, FinancialInstitution institution, InputStream qif, InputStream investment) {
    List<Message> messages = new ArrayList<Message>();
    Collection<NameValuePair<Register, List<Message>>> loaded = collectInvestments(investment, parse(qif));
    Iterator<NameValuePair<Register, List<Message>>> parsed = loaded.iterator();
    NameValuePair<Register, List<Message>> accountRegister = parsed.next();
    Account account = createAccount(locale, institution, accountRegister, messages);
    while (parsed.hasNext()) {
      process(parsed.next(), account, messages);
    }
    return messages;
  }
View Full Code Here

    return stripped;
  }

  protected Account createAccount(Locale locale, FinancialInstitution institution, NameValuePair<Register, List<Message>> register, List<Message> messages) {
    messages.addAll(register.getValue());
    Account account = createAccount(locale, institution, register.getKey());
    messages.add(new Message(register.getKey(), MESSAGE_ACCOUNT_CREATED, account.getName() + "[" + account.getId() + "]"));
    return account;
  }
View Full Code Here

    messages.add(new Message(register.getKey(), MESSAGE_ACCOUNT_CREATED, account.getName() + "[" + account.getId() + "]"));
    return account;
  }

  protected Account createAccount(Locale locale, FinancialInstitution institution, Register register) {
    Account account = new Account();
    account.setLocale(locale);
    account.setHeldAt(institution);
    account.setClosed(Boolean.FALSE);
    account.setFavorite(Boolean.TRUE);
    account.setLastModified(new Date());
    account.setName(register.getTargetAccount());
    account.setCreated(account.getLastModified());
    account.setOwner(UserDetails.findCurrentUser());
    account.setAccountType(getAccountType(register));
    account.setOpened(DateUtils.getMidnight(register.getDate()));
    account.setInitialBalance(new BigDecimal(register.getAmount()));
    account.persist();
    register.setPayee(account.getName());
    getOrCreatePayee(register, account);
    return account;
  }
View Full Code Here

    Register register = new Register();
    register.setAmount(20D);
    register.setDate(new Date());
    register.setTargetAccount("Test account");
    register.setType(Register.AccountType.BANK);
    Account account = qifImporterService.createAccount(Locale.US, institution, register);
    assertNotNull("Account created", account);
    assertEquals("Amount processed", new Double(20), new Double(account.calculateBalance().doubleValue()));
    assertEquals("Account name processed", "Test account", account.getName());
    assertEquals("Financial institution processed", institution, account.getHeldAt());
    assertTrue("User correctly assumed", account.belongsTo(UserDetails.findCurrentUser()));
  }
View Full Code Here

  }

  @Test
  public void testGetOrCreatePayee() {
    Register register = new Register();
    Account account = Account.findAccount(1L);
    register.setPayee("john");
    assertTrue("Payee created", qifImporterService.getOrCreatePayee(register, account).getId() > 0);
  }
View Full Code Here

    register.setPayee("Someone");
    register.setCategory("newcat");
    register.setSubcategory("newsub");
    register.setDescription("a transaction");
    register.setOperation(Register.Operation.DEPOSIT_OR_WITHDRAWAL);
    Account account = Account.findAccount(1L);
    int number = account.getTransactions().size();
    qifImporterService.process(register, account);
    assertEquals("Transaction saved", number + 1, account.getTransactions().size());
    register.setPrice(98.34);
    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

        assertEquals("Positive amount with exhange rates", BigDecimal.TEN, accountService.calculateTargetAmount(BigDecimal.ONE, -10));
    }

    @Test
    public void testTransferMoney() {
        Account origin = Account.findAccount(1L);
        Account target = Account.findAccount(2L);
        assertEquals("Six initial transactions", 6, origin.getTransactions().size());
        assertEquals("Two initial transactions", 2, target.getTransactions().size());
        UserDetails user = new UserDetails();
        accountService.transferMoney(user, origin, target, null, BigDecimal.ZERO, BigDecimal.ZERO, 0, null);
        assertEquals("Six initial transactions", 6, origin.getTransactions().size());
        assertEquals("Two initial transactions", 2, target.getTransactions().size());
        user = origin.getOwner();
        accountService.transferMoney(user, origin, target, new Date(), BigDecimal.ONE, BigDecimal.ZERO, 1, null);
        assertEquals("One transaction added to origin", 7, origin.getTransactions().size());
        assertEquals("One transaction added to target", 3, target.getTransactions().size());
        accountService.transferMoney(user, origin, target, new Date(), BigDecimal.ONE, BigDecimal.ONE, 1, null);
        assertEquals("Two transactions added to origin", 9, origin.getTransactions().size());
        assertEquals("One more transaction added to target", 4, target.getTransactions().size());
    }
View Full Code Here

TOP

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

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.