Esempio n. 1
0
  private void createOperations(Date startDate, int numberOfDays, Context context) {
    for (int i = 0; i < numberOfDays; i++) {
      Date date = DateUtils.addDays(startDate, i);

      if (i % 7 == 0) {
        income(date, context.accounts.get(0), context.salaryCategory, new BigDecimal("16000"));
      }
      if (i % 5 == 0) {
        income(
            date,
            context.accounts.get(1),
            context.otherIncomeCategory,
            new BigDecimal(1000 + Math.round(Math.random() * 5000)));
      }

      for (int j = 0; j < Math.random() * 7; j++) {
        expense(date, context.accounts.get(1), context);
        if (j % 2 == 0) expense(date, context.accounts.get(0), context);
      }

      if (i % 2 == 0) {
        Account account2 =
            context.accounts.get((int) (1 + Math.random() * (context.accounts.size() - 1)));
        transfer(date, context.accounts.get(0), account2);
      }
    }
  }
Esempio n. 2
0
  private void expense(final Date date, final Account account, final Context context) {
    persistence.runInTransaction(
        em -> {
          int categoryIdx =
              (int) Math.round(Math.random() * (context.expenseCategories.size() - 1));
          Category category = context.expenseCategories.get(categoryIdx);
          if (category == null) return;

          int categoryWeight = context.expenseCategories.size() - categoryIdx;
          BigDecimal amount = randomExpenseAmount(account, date, 0.1 + (categoryWeight * 0.05));
          if (BigDecimal.ZERO.compareTo(amount) >= 0) return;

          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.EXPENSE);
          operation.setOpDate(date);
          operation.setAcc1(account);
          operation.setCategory(category);
          operation.setAmount1(amount);
          em.persist(operation);

          log.info("Expense: " + date + ", " + account.getName() + ", " + amount);
        });
  }