Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.Subcategory


    protected Map<Currency, Map<Subcategory, BigDecimal>> organizeByCategory(List<AccountTransaction> transactions) {
      Map<Currency, Map<Subcategory, BigDecimal>> data = new HashMap<Currency, Map<Subcategory, BigDecimal>>();
      if (!CollectionUtils.isEmpty(transactions)) {
            for (AccountTransaction transaction : transactions) {
                Subcategory category = transaction.getSubcategory();
                if (!category.getParentCategory().isIncome()) {
                    BigDecimal amount = transaction.getAmount();
                    Currency currency = Currency.getInstance(transaction.getAccount().getLocale());
                    if (!data.containsKey(currency)) {
                        data.put(currency, new HashMap<Subcategory, BigDecimal>());
                    }
View Full Code Here


    }

    @RequestMapping(value = "/manage", method = RequestMethod.POST)
    public String manage(String currency, long subcategory, int month, double amount, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      Subcategory loaded = Subcategory.findSubcategory(subcategory);
      if (month == -1) {
        for (int i = 0; i < 12; i++) {
          createBudget(user, currency, i, amount, loaded);
        }
      } else {
View Full Code Here

      amount = amount.abs().add(transaction.getAmount().abs());
      categoryData.put(transaction.getSubcategory(), amount);
    }

    protected final Map<Subcategory, BigDecimal> getOrCreateCategoryData(final AccountTransaction transaction, final Map<Category, Map<Subcategory, BigDecimal>> data) {
      Subcategory subcategory = transaction.getSubcategory();
      Category category = subcategory.getParentCategory();
      Map<Subcategory, BigDecimal> categoryData = data.get(category);
      if (categoryData == null) {
        categoryData = new HashMap<Subcategory, BigDecimal>();
        data.put(category, categoryData);
      }
View Full Code Here

      }
      return categoryData;
    }

    protected BigDecimal getOrCreateSubcategoryAmount(final AccountTransaction transaction, final Map<Subcategory, BigDecimal> categoryData) {
      Subcategory subcategory = transaction.getSubcategory();
      BigDecimal amount = categoryData.get(subcategory);
      if (amount == null) {
        amount = BigDecimal.ZERO;
        categoryData.put(subcategory, amount);
      }
View Full Code Here

    @RequestMapping("/categories-chart/{id}/{intervals}")
    public String expensesByCategoryOverTimeChartData(@PathVariable final Long id, @PathVariable final String intervals, final ModelMap modelMap) {
      UserDetails user = getCurrentUser();
      Interval interval = getInterval(intervals);
      Subcategory subcat = Subcategory.findSubcategory(id);
      Map<String, BigDecimal> maxValues = cache.getMaxCategoryData(user, subcat, intervals);
      Map<String, Map<Date, NameValuePair<Date, BigDecimal>>> budgetData = cache.getAlloted(user, subcat, intervals);
      Map<String, Map<Date, NameValuePair<Date, BigDecimal>>> currencyData = cache.getCategoryData(user, subcat, intervals);
      if (maxValues == null) {
        maxValues = new HashMap<String, BigDecimal>();
View Full Code Here

@Transactional
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);
    }
    amount = amount.abs();
    if ("category.investment.buy".equals(subcat)) {
      amount = amount.negate();
    }
    transaction.getPrice().addTransaction(transaction);
    transaction.getAccountTransaction().setAmount(amount);
    transaction.getAccountTransaction().setAccount(account);
    transaction.getAccountTransaction().setPayee(investment);
    transaction.getAccountTransaction().setInvestment(transaction);
    transaction.getAccountTransaction().setSubcategory(subcategory);
    transaction.getAccountTransaction().persist();
    if (commision != 0D) {
      BigDecimal charge = new BigDecimal(commision).abs();
      Subcategory chargeCategory = Subcategory.findBySubcategory("category.bankcharges", user);
      AccountTransaction bankCharge = AccountTransaction.createInstance(account, Payee.findByFinancialInstitution(account.getHeldAt()), chargeCategory, charge, DateUtils.nextDate(transaction.getAccountTransaction().getOperationDate()), null);
      bankCharge.persist();
    }
  }
View Full Code Here

    assertNotNull("Data stored", cache.getIncomeVsExpensesOverTime(user, 11));
  }

  @Test
  public void testCategoryData() {
    Subcategory category = new Subcategory();
    category.setId(1L);
    String intervals = "LAST_QUARTER";
    assertNull("Data not stored", cache.getCategoryData(user, category, intervals));
    cache.storeCategoryData(user, category, intervals, new HashMap<String, Map<Date, NameValuePair<Date, BigDecimal>>>());
    assertNotNull("Data stored", cache.getCategoryData(user, category, intervals));
  }
View Full Code Here

    assertNotNull("Data stored", cache.getCategoryData(user, category, intervals));
  }

  @Test
  public void testMaxCategoryData() {
    Subcategory category = new Subcategory();
    category.setId(1L);
    String intervals = "LAST_QUARTER";
    assertNull("Data not stored", cache.getMaxCategoryData(user, category, intervals));
    cache.storeMaxCategoryData(user, category, intervals, new HashMap<String, BigDecimal>());
    assertNotNull("Data stored", cache.getMaxCategoryData(user, category, intervals));
  }
View Full Code Here

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

    String type = register.getType().toString();
    return AccountType.findAccountTypeByKey(type);
  }

  protected Subcategory getOrCreateSubcategory(UserDetails user, Register register) {
    Subcategory subcategory = Subcategory.findBySubcategory(register.getSubcategory(), user);
    if (subcategory == null) {
      Category category = Category.findByCategory(register.getCategory());
      if (category == null) {
        category = new Category();
        category.setCategory(register.getCategory());
        category.setIncome(register.getAmount() > 0 ? Boolean.TRUE : Boolean.FALSE);
        category.persist();
      }
      subcategory = new Subcategory();
      subcategory.setOwner(user);
      subcategory.setParentCategory(category);
      subcategory.setCategory(register.getSubcategory());
      subcategory.persist();
    }
    return subcategory;
  }
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.