Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.Account


        assertEquals("One more transaction added to target", 4, target.getTransactions().size());
    }

    @Test
    public void testIsValidTransaction() {
        Account account = new Account();
        account.setClosed(Boolean.FALSE);
        UserDetails user = new UserDetails();
        user.setUsername("someuser");
        Calendar calendar = Calendar.getInstance();
        Date now = calendar.getTime();
        calendar.add(Calendar.YEAR, -1);
        account.setOpened(calendar.getTime());
        assertFalse("Null user", accountService.isValidTransaction(null, account, now, BigDecimal.ZERO));
        assertFalse("Null account", accountService.isValidTransaction(user, null, now, BigDecimal.ZERO));
        assertFalse("Not belongs", accountService.isValidTransaction(user, account, now, BigDecimal.ONE));
        account.setOwner(user);
        assertFalse("Null date", accountService.isValidTransaction(user, account, null, BigDecimal.ONE));
        assertFalse("Null amount", accountService.isValidTransaction(user, account, now, null));
        assertFalse("Zero amount", accountService.isValidTransaction(user, account, now, BigDecimal.ZERO));
        assertTrue("Transaction ok", accountService.isValidTransaction(user, account, now, BigDecimal.ONE));
    }
View Full Code Here


      bill.setPayee(Payee.findMySelf(user));
      bill.setPeriod(RECURRING_INTERVAL.MONTHLY);
      bill.setCategory(Subcategory.findSubcategory(1L));
      bill.setDescription("a bill");
      bill.persist();
      Account account = Account.findAccount(3L);
      int transactions = account.getTransactions().size();
      accountService.payBill(user, bill, 3L, 101D, new Date());
      assertNotNull("Bill updated", bill.getLastPayment());
      assertTrue("Transaction created", (transactions + 1) == account.getTransactions().size());
    }
View Full Code Here

    assertEquals("Icon URL persisted", "http://www.google.com/logo", institution.getIcon());
  }

  @Test
  public void testQif() {
    Account account = Account.findAccount(1L);
    NameValuePair<String, String> qifs = service.qif(account);
    assertNull("No investments", qifs.getValue());
    assertEquals("Transactions parsed", "!Type:Bank\nD20/08'2010\nT53.00\nCX\nPOpening Balance\nL[Cuenta corriente]\n^\nD03/11'2010\nT-100.00\nPJose\nLcategory.financial:Bank charges\n^\nD25/11'2010\nT-26.00\nPJose\nLcategory.financial:Bank charges\n^\nD30/11'2010\nT785.00\nPJose\nLcategory.salary:category.wages\n^\nD10/01'2011\nT-53.00\nPJose\nLcategory.household:category.furnishing\n^\nD20/01'2011\nT-93.00\nPJose\nLcategory.household:category.dues\n^\nD14/06'2011\nT-215.00\nPJose\nLcategory.financial:Bank charges\n^\n", qifs.getKey());
  }
View Full Code Here

  }

  @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

        boolean withdrawal = register.getAmount() < 0;
        String subcat = withdrawal ? "category.transfer.out" : "category.transfer.in";
        if (account.isCreditCard() & !withdrawal) {
          subcat = "category.cc.payment.in";
        } else {
          Account targetAccount = Account.findAccount(register.getTargetAccount(), account.getOwner());
          if ((targetAccount != null) && (targetAccount.isCreditCard())) {
            subcat = "category.cc.payment.out";
          }
        }
        if (subcat.endsWith("in")) {
          transaction.setPayee(Payee.findMySelf(account.getOwner()));
View Full Code Here

@Transactional
public final class AccountService implements org.internna.ossmoney.services.AccountService {

    @Override public void transferMoney(Long origin, Long target, Date operationDate, BigDecimal amount, BigDecimal chargeAmount, double rate, String memo) {
        UserDetails user = UserDetails.findCurrentUser();
        Account originAccount = Account.findAccount(origin);
        Account targetAccount = Account.findAccount(target);
        transferMoney(user, originAccount, targetAccount, operationDate, amount, chargeAmount, rate, memo);
    }
View Full Code Here

    @Override public long addTransaction(AccountTransaction transaction) {
        long accountId = -1;
        UserDetails user = UserDetails.findCurrentUser();
        if (transaction.getAccount() != null) {
            accountId = transaction.getAccount().getId();
            Account account = Account.findAccount(accountId);
            if (isValidTransaction(user, account, transaction.getOperationDate(), transaction.getAmount())) {
                transaction.setAccount(account);
                if (transaction.getPayee() != null) {
                    transaction.setPayee(Payee.entityManager().getReference(Payee.class, transaction.getPayee().getId()));
                }
                if (transaction.getSubcategory() != null) {
                    transaction.setSubcategory(Subcategory.entityManager().getReference(Subcategory.class, transaction.getSubcategory().getId()));
                }
                transaction.persist();
                account.setLastModified(new Date());
                account.merge();
            }
        }
        return accountId;
    }
View Full Code Here

    incomeTransfer.setOriginOfTheFunds(origin.getName());
    incomeTransfer.persist();
  }

  @Override public void payBill(UserDetails user, Bill bill, Long origin, Double amount, Date operationDate) {
    Account account = Account.findAccount(origin);
    BigDecimal total = new BigDecimal(amount).abs().negate();
    AccountTransaction transaction = AccountTransaction.createInstance(account, bill.getPayee(), bill.getCategory(), total, operationDate, "");
    bill.updatePayment(operationDate);
    bill.merge();
    transaction.persist();
View Full Code Here

    assertNotNull("Cache updated", cache.getIncomeAndExpenses(user, "last_quarter"));
  }

  @Test
  public void testCalculateIncomeAndExpenses() {
    Account account = new Account();
        account.setLocale(Locale.GERMANY);
        Account usAccount = new Account();
        usAccount.setLocale(Locale.US);
        List<AccountTransaction> transactions = null;
        Map<Currency, NameValuePair<BigDecimal, BigDecimal>> data = controller.calculateIncomeAndExpenses(transactions);
        transactions = new ArrayList<AccountTransaction>();
        AccountTransaction transaction = new AccountTransaction();
        transaction.setAccount(account);
        transaction.setOperationDate(new Date());
        transaction.setAmount(BigDecimal.TEN);
        transactions.add(transaction);
        data = controller.calculateIncomeAndExpenses(transactions);
        assertEquals("Some income", BigDecimal.TEN, data.get(Currency.getInstance(account.getLocale())).getKey());
        AccountTransaction expense = new AccountTransaction();
        expense.setOperationDate(new Date());
        expense.setAmount(new BigDecimal(-4));
        expense.setAccount(account);
        transactions.add(expense);
        data = controller.calculateIncomeAndExpenses(transactions);
        assertEquals("An expense", new BigDecimal(4), data.get(Currency.getInstance(account.getLocale())).getValue());
        AccountTransaction otherExpense = new AccountTransaction();
        otherExpense.setAccount(account);
        otherExpense.setOperationDate(new Date());
        otherExpense.setAmount(new BigDecimal(-6));
        transactions.add(otherExpense);
        data = controller.calculateIncomeAndExpenses(transactions);
        assertEquals("Several expenses", BigDecimal.TEN, data.get(Currency.getInstance(account.getLocale())).getValue());
        AccountTransaction usTransaction = new AccountTransaction();
        usTransaction.setAccount(usAccount);
        usTransaction.setOperationDate(new Date());
        usTransaction.setAmount(BigDecimal.ONE);
        transactions.add(usTransaction);
        data = controller.calculateIncomeAndExpenses(transactions);
        assertEquals("Some $ income", BigDecimal.ONE, data.get(Currency.getInstance(usAccount.getLocale())).getKey());
    }
View Full Code Here

        expense.setIncome(Boolean.FALSE);
        Subcategory fooExpense = new Subcategory();
        fooExpense.setId(1L);
        fooExpense.setParentCategory(expense);
        fooExpense.setCategory("fooExpense");
        Account account = new Account();
        account.setLocale(Locale.GERMANY);
        Account usAccount = new Account();
        usAccount.setLocale(Locale.US);
        List<AccountTransaction> transactions = null;
        Map<Currency, Map<Subcategory, BigDecimal>> data = controller.organizeByCategory(transactions);
        assertEquals("No data organized", 0, data.size());
        transactions = new ArrayList<AccountTransaction>();
        AccountTransaction transaction = new AccountTransaction();
        transaction.setAccount(account);
        transaction.setOperationDate(new Date());
        transaction.setAmount(BigDecimal.TEN);
        transaction.setSubcategory(fooIncome);
        transactions.add(transaction);
        data = controller.organizeByCategory(transactions);
        assertEquals("No expense data", 0, data.size());
        AccountTransaction expensetransaction = new AccountTransaction();
        expensetransaction.setAccount(account);
        expensetransaction.setOperationDate(new Date());
        expensetransaction.setAmount(new BigDecimal(-75));
        expensetransaction.setSubcategory(fooExpense);
        transactions.add(expensetransaction);
        data = controller.organizeByCategory(transactions);
        assertEquals("Some expense data", 1, data.size());
        assertEquals("Some categories", 1, data.get(Currency.getInstance(account.getLocale())).size());
        assertEquals("Some total amount", new BigDecimal(75), data.get(Currency.getInstance(account.getLocale())).get(fooExpense));
        AccountTransaction otherExpenseInCategory = new AccountTransaction();
        otherExpenseInCategory.setAccount(account);
        otherExpenseInCategory.setOperationDate(new Date());
        otherExpenseInCategory.setAmount(new BigDecimal(-75));
        otherExpenseInCategory.setSubcategory(fooExpense);
        transactions.add(otherExpenseInCategory);
        data = controller.organizeByCategory(transactions);
        assertEquals("Same categories", 1, data.get(Currency.getInstance(account.getLocale())).size());
        assertEquals("Added total amount", new BigDecimal(150), data.get(Currency.getInstance(account.getLocale())).get(fooExpense));
        AccountTransaction otherExpense = new AccountTransaction();
        otherExpense.setAccount(usAccount);
        otherExpense.setOperationDate(new Date());
        otherExpense.setAmount(new BigDecimal(-75));
        otherExpense.setSubcategory(fooExpense);
        transactions.add(otherExpense);
        data = controller.organizeByCategory(transactions);
        assertEquals("Two currencies", 2, data.size());
        assertEquals("Added total amount", new BigDecimal(75), data.get(Currency.getInstance(usAccount.getLocale())).get(fooExpense));
        Category expense2 = new Category();
        expense2.setIncome(Boolean.FALSE);
        Subcategory fooExpense2 = new Subcategory();
        fooExpense2.setId(2L);
        fooExpense2.setParentCategory(expense2);
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.