@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String edit(InvestmentTransaction transaction, ModelMap modelMap) {
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();
}