Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.Subcategory


    }

    protected void transferMoney(UserDetails user, Account origin, Account target, Date operationDate, BigDecimal amount, BigDecimal chargeAmount, double rate, String memo) {
        if (isValidTransfer(user, origin, target, operationDate, amount)) {
            Payee payee = Payee.findMySelf(user);
            Subcategory transferCategory = Subcategory.findBySubcategory("category.transfer.out", user);
            Subcategory transferInCategory = Subcategory.findBySubcategory("category.transfer.in", user);
            AccountTransaction send = AccountTransaction.createInstance(origin, payee, transferCategory, calculateAmount(amount), operationDate, memo);
            AccountTransaction receive = AccountTransaction.createInstance(target, payee, transferInCategory, calculateTargetAmount(amount, rate), operationDate, memo);
            receive.setOriginOfTheFunds(origin.getName());
            send.persist();
            receive.persist();
            if ((chargeAmount != null) && (!BigDecimal.ZERO.equals(chargeAmount))) {
              Subcategory chargeCategory = Subcategory.findBySubcategory("category.bankcharges", user);
                AccountTransaction charge = AccountTransaction.createInstance(origin, Payee.findByFinancialInstitution(origin.getHeldAt()), chargeCategory, calculateAmount(chargeAmount), DateUtils.nextDate(operationDate), memo);
                charge.persist();
            }
            Date now = new Date();
            origin.setLastModified(now);
View Full Code Here


      AccountTransaction transaction = AccountTransaction.findAccountTransaction(Long.parseLong(id));
      transaction.setReconciled(Boolean.TRUE);
      amount = amount.add(transaction.getAmount().abs());
      transaction.merge();
    }
    Subcategory transferCategory = Subcategory.findBySubcategory("category.transfer.out", user);
    AccountTransaction transfer = AccountTransaction.createInstance(origin, Payee.findByName(account.getName()), transferCategory, amount, date, null);
    transfer.persist();
    Subcategory transferInCategory = Subcategory.findBySubcategory("category.transfer.in", user);
    AccountTransaction incomeTransfer = AccountTransaction.createInstance(account, Payee.findMySelf(user), transferInCategory, amount, date, null);
    incomeTransfer.setOriginOfTheFunds(origin.getName());
    incomeTransfer.persist();
  }
View Full Code Here

    @Test
    public void testOrganizeByCategory() {
        Category income = new Category();
        income.setIncome(Boolean.TRUE);
        Subcategory fooIncome = new Subcategory();
        fooIncome.setParentCategory(income);
        Category expense = new Category();
        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);
        fooExpense2.setCategory("fooExpense2");
        AccountTransaction otherExpenseInNewCategory = new AccountTransaction();
        otherExpenseInNewCategory.setAccount(account);
        otherExpenseInNewCategory.setOperationDate(new Date());
        otherExpenseInNewCategory.setAmount(new BigDecimal(-75));
        otherExpenseInNewCategory.setSubcategory(fooExpense2);
View Full Code Here

    date = calendar.getTime();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    Category category = new Category();
    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();
View Full Code Here

  public void init() {
    category = new Category();
    category.setId(100L);
    category.setIncome(Boolean.TRUE);
    category.setCategory("category");
    subcategory = new Subcategory();
    subcategory.setId(1000L);
    subcategory.setCategory("subcategory");
    subcategory.setParentCategory(category);
    otherSubcategory = new Subcategory();
    otherSubcategory.setId(1001L);
    otherSubcategory.setParentCategory(category);
    otherSubcategory.setCategory("otherSubcategory");
    otherCategory = new Category();
    otherCategory.setId(101L);
    otherCategory.setIncome(Boolean.TRUE);
    otherCategory.setCategory("otherCategory");
    thirdSubcategory = new Subcategory();
    thirdSubcategory.setId(1002L);
    thirdSubcategory.setCategory("thirdSubcategory");
    thirdSubcategory.setParentCategory(otherCategory);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -2);
View Full Code Here

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

      Budget budget = new Budget();
      MonthlyBudget monthlyBudget = new MonthlyBudget();
      monthlyBudget.setBudgetedMonth(6);
      CategoryBudget categoryBudget = new CategoryBudget();
      CategoryBudget categoryBudget2 = new CategoryBudget();
      Subcategory subcategory = Subcategory.findSubcategory(1L);
      Subcategory subcategory2 = Subcategory.findSubcategory(3L);
      categoryBudget.setLocale(locale);
      categoryBudget2.setLocale(locale);
      categoryBudget.setCategory(subcategory);
      categoryBudget2.setCategory(subcategory2);
      categoryBudget.setExpectedAmount(BigDecimal.TEN);
View Full Code Here

TOP

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

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.