Package org.internna.ossmoney.model

Examples of org.internna.ossmoney.model.AccountTransaction


      UserDetails user = UserDetails.findCurrentUser();
      InvestmentTransaction loaded = InvestmentTransaction.findInvestmentTransaction(transaction.getId());
      Account account = loaded.getAccountTransaction().getAccount();
      if (account.belongsTo(user)) {
        cache.invalidate(user);
        AccountTransaction accountTransaction = loaded.getAccountTransaction();
        if (transaction.getPrice() != null) {
          loaded.setQuantity(transaction.getQuantity());
          loaded.getPrice().setPrice(transaction.getPrice().getPrice());
          accountTransaction.setAmount(new BigDecimal(transaction.getQuantity() * transaction.getPrice().getPrice()));
        } else {
          loaded.setPrice(null);
          accountTransaction.setAmount(transaction.getAccountTransaction().getAmount());
        }
        Investment investment = Investment.findInvestment(transaction.getInvestment().getId());
        loaded.setInvestment(investment);
        loaded.getAccountTransaction().setPayee(investment)
        accountTransaction.setOperationDate(transaction.getAccountTransaction().getOperationDate());
        accountTransaction.setReferenceNumber(transaction.getAccountTransaction().getReferenceNumber());
        accountTransaction.setSubcategory(Subcategory.findBySubcategory(transaction.getAccountTransaction().getSubcategory().getCategory(), user));
        loaded.merge();
      }
      return "redirect:/financial/accounts/" + account.getId();
    }
View Full Code Here


    public String remove(@PathVariable Long id, ModelMap modelMap) {
      Long accountId = null;
      UserDetails user = UserDetails.findCurrentUser();
      InvestmentTransaction transaction  = InvestmentTransaction.findInvestmentTransaction(id);
      if (transaction != null) {
        AccountTransaction accountTransaction = transaction.getAccountTransaction();
        Account account = accountTransaction.getAccount();
        if (account.belongsTo(user)) {
          cache.invalidate(user);
          accountId = account.getId();
          accountTransaction.remove();
        }
      }
      return "redirect:/financial/accounts/" + (accountId != null ? accountId : "");
    }
View Full Code Here

    @RequestMapping("/view-transaction/{id}")
    public String viewTransaction(@PathVariable Long id, ModelMap modelMap) {
      String jsp = "accounts/view-transaction";
      UserDetails user = fillTransactionModel(modelMap);
      AccountTransaction accountTransaction = AccountTransaction.findAccountTransaction(id);
      if ((accountTransaction != null) &&  (accountTransaction.isInvestmentTransaction())) {
        jsp = "redirect:/financial/investments/view/" + accountTransaction.getInvestment().getId();
      } else if ((accountTransaction != null) && (accountTransaction.getAccount().belongsTo(user))) {
        modelMap.addAttribute("transaction", accountTransaction);
      }
      return jsp;
    }
View Full Code Here

    }

    @RequestMapping(value = "/edit-transaction", method = RequestMethod.POST)
    public String editTransaction(AccountTransaction transaction, ModelMap modelMap) {
      UserDetails user = UserDetails.findCurrentUser();
      AccountTransaction loaded = AccountTransaction.findAccountTransaction(transaction.getId());
      if (loaded.getAccount().belongsTo(user)) {
        cache.invalidate(user);
        loaded.setMemo(transaction.getMemo());
        loaded.setAmount(transaction.getAmount());
        loaded.setOperationDate(transaction.getOperationDate());
        loaded.setReferenceNumber(transaction.getReferenceNumber());
        loaded.setPayee(Payee.findPayee(transaction.getPayee().getId()));
        loaded.setSubcategory(Subcategory.findSubcategory(transaction.getSubcategory().getId()));
        loaded.merge();
      }
      return details(loaded.getAccount().getId(), modelMap);
    }
View Full Code Here

    }

    @RequestMapping("/remove/{id}")
    public String remove(@PathVariable Long id, ModelMap modelMap) {
      Account account = null;
      AccountTransaction transaction  = AccountTransaction.findAccountTransaction(id);
      if (transaction != null) {
        account = transaction.getAccount();
        if (account.belongsTo(UserDetails.findCurrentUser())) {
          transaction.remove();
        }
      }
      return details(account, modelMap);
    }
View Full Code Here

    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

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

  }

  protected Message process(Register register, Account account) {
    Message message = new Message(register, MESSAGE_TRANSACTION_CREATED);
    if ((register != null) && (!register.isSkipped())) {
      AccountTransaction transaction = new AccountTransaction();
      transaction.setAccount(account);
      transaction.setMemo(register.getDescription());
      transaction.setOperationDate(register.getDate());
      transaction.setAmount(new BigDecimal(register.getAmount()));
      if (Register.Operation.DEPOSIT_OR_WITHDRAWAL.equals(register.getOperation())) {
        transaction.setReconciled(register.getReconciled());
        transaction.setPayee(getOrCreatePayee(register, account));
        transaction.setSubcategory(getOrCreateSubcategory(account.getOwner(), register));
      } else if (register.isInvestment()) {
        transaction.setReconciled(Boolean.FALSE);
        Investment investment = getOrCreateInvestment(register, account);
        transaction.setPayee(investment);
        InvestmentTransaction investmentTransaction = new InvestmentTransaction();
        investment.addInvestment(investmentTransaction);
        investmentTransaction.setAccountTransaction(transaction);
        if (register.getPrice() != null) {
          investmentTransaction.setPrice(new InvestmentPrice());
          investmentTransaction.getPrice().setInvestment(investment);
          investmentTransaction.getPrice().setPrice(register.getPrice());
          investmentTransaction.getPrice().setUpdateTime(transaction.getOperationDate());
          investmentTransaction.setQuantity(register.getQuantity());
        } else {
          investmentTransaction.setPrice(null);
          investmentTransaction.setQuantity(new Double(0D));
        }
        transaction.setInvestment(investmentTransaction);
        String subcat = Register.Operation.BUY.equals(register.getOperation()) ? "category.investment.buy" : Register.Operation.SELL.equals(register.getOperation()) ? "category.investment.sell" : "category.investment.interest";
        if (Register.Operation.BUY.equals(register.getOperation())) {
          transaction.setAmount(transaction.getAmount().negate());
        }
        transaction.setSubcategory(Subcategory.findBySubcategory(subcat, account.getOwner()));
      } else {
        transaction.setReconciled(Boolean.FALSE);
        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()));
          transaction.setOriginOfTheFunds(register.getTargetAccount());
        } else {
          register.setPayee(register.getTargetAccount());
          transaction.setPayee(getOrCreatePayee(register, account));
        }
        transaction.setSubcategory(Subcategory.findBySubcategory(subcat, account.getOwner()));
      }
      transaction.persist();
      message.setConfiguration(dFormat.format(transaction.getOperationDate()) + " " + transaction.getPayee().getName() + " " + nFormat.format(transaction.getAmount()));
    }
    return message;
  }
View Full Code Here

    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);
            target.setLastModified(now);
            origin.merge();
View Full Code Here

  }

  @Override public void balance(UserDetails user, Account account, Account origin, Date date, String[] transactions) {
    BigDecimal amount = BigDecimal.ZERO;
    for (String id : transactions) {
      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

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.