Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.AccountTransaction


  }

  @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


    category.setIncome(Boolean.TRUE);
    category.setCategory("category");
    Subcategory subcategory = new Subcategory();
    subcategory.setParentCategory(category);
    subcategory.setCategory("subcategory");
    transaction = new AccountTransaction();
    transaction.setAmount(BigDecimal.TEN);
    transaction.setSubcategory(subcategory);
    transaction.setOperationDate(date);
    Account account = new Account();
    account.setLocale(Locale.US);
View Full Code Here

        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

        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);
        fooExpense2.setCategory("fooExpense2");
        AccountTransaction otherExpenseInNewCategory = new AccountTransaction();
        otherExpenseInNewCategory.setAccount(account);
        otherExpenseInNewCategory.setOperationDate(new Date());
        otherExpenseInNewCategory.setAmount(new BigDecimal(-75));
        otherExpenseInNewCategory.setSubcategory(fooExpense2);
        transactions.add(otherExpenseInNewCategory);
        data = controller.organizeByCategory(transactions);
        assertEquals("Two categories", 2, data.get(Currency.getInstance(account.getLocale())).size());
        assertEquals("Total amount not changed", new BigDecimal(150), data.get(Currency.getInstance(account.getLocale())).get(fooExpense));
        assertEquals("More amounts", new BigDecimal(75), data.get(Currency.getInstance(account.getLocale())).get(fooExpense2));
View Full Code Here

        usAccount.setInitialBalance(BigDecimal.ONE);
        Set<Account> accounts = new java.util.HashSet<Account>(2);
        accounts.add(account);
        accounts.add(usAccount);
        calendar.add(Calendar.MONTH, 1);
        AccountTransaction transaction = new AccountTransaction();
        transaction.setAccount(account);
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -1);
        transaction.setOperationDate(calendar.getTime());
        transaction.setAmount(BigDecimal.TEN);
        Date[] dates = DateUtils.dates(5);
        Map<Currency, Map<Date, IncomeExpense>> data = controller.calculateWealth(dates, accounts);
        assertEquals("Two currencies", 2, data.size());
        assertEquals("Before creation", BigDecimal.ZERO, data.get(Currency.getInstance(account.getLocale())).get(dates[0]).getKey());
        assertEquals("Added transactions", new BigDecimal(20), data.get(Currency.getInstance(Locale.GERMANY)).get(dates[5]).getKey());
View Full Code Here

  @Test
  @SuppressWarnings("deprecation")
  public void testGetAsJSONString() {
    Account account = Account.findAccount(1L);
    AccountTransaction transaction = new AccountTransaction();
    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);
    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.AccountTransaction

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.