Package org.internna.ossmoney.model.qif

Examples of org.internna.ossmoney.model.qif.Message


    }
    return result;
  }

  protected Message parse(Register register, String line) {
    Message message = new Message(register, MESSAGE_PARSE_LINE, line);
    try {
      char delimiter = line.charAt(0);
      switch (delimiter) {
        case '!':  register.setOperation(Register.Operation.OPEN_BALANCE);
              register.setType(Register.AccountType.valueOf(line.substring(6).trim().toUpperCase(Locale.UK)));
              break;
        case 'D':  Calendar calendar = Calendar.getInstance();
              calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(line.substring(1, 3)));
              calendar.set(Calendar.MONTH, Integer.parseInt(line.substring(4, 6)) - 1);
              calendar.set(Calendar.YEAR, Integer.parseInt(line.substring(7, 11)));
              register.setDate(calendar.getTime());
              break;
        case 'L'if ('[' == line.charAt(1)) {
                if (!Register.Operation.OPEN_BALANCE.equals(register.getOperation())) {
                  register.setOperation(Register.Operation.TRANSFER);
                }
                register.setTargetAccount(stripCash(line));
              } else {
                int separator = line.indexOf(':');
                if (separator < 0) {
                  register.setCategory(line.substring(1).trim());
                  register.setSubcategory(register.getCategory());
                } else {
                  register.setCategory(line.substring(1, separator).trim());
                  register.setSubcategory(line.substring(separator + 1).trim());
                }
              }
              break;
        case 'C':  register.setReconciled(Boolean.TRUE);
              break;
        case 'P':  register.setPayee(stripCash(line));
              break;
        case 'Y':  register.setInvestment(line.substring(1).trim());
              break;
        case 'M':  register.setDescription(line.substring(1).trim());
              break;
        case 'T':  register.setAmount(getDouble(line.substring(1).trim()));
              break;
        case 'N':  String operation = line.substring(1).trim();
              register.setOperation(Register.Operation.fromValue(operation));
              break;
        case 'Q'if (line.length() > 1) {
                register.setQuantity(getDouble(line.substring(1).trim()));
              }
              break;
        case 'I'if (line.length() > 1) {
                register.setPrice(getDouble(line.substring(1).trim()));
              }
              break;
        case 'S':  register.setSkipped(Boolean.TRUE);
              break;
      }
    } catch (Exception ex) {
      message.setResult(false);
      message.setMessageKey(MESSAGE_PARSE_LINE_ERROR);
    }
    return message;
  }
View Full Code Here


  }

  protected Account createAccount(Locale locale, FinancialInstitution institution, NameValuePair<Register, List<Message>> register, List<Message> messages) {
    messages.addAll(register.getValue());
    Account account = createAccount(locale, institution, register.getKey());
    messages.add(new Message(register.getKey(), MESSAGE_ACCOUNT_CREATED, account.getName() + "[" + account.getId() + "]"));
    return account;
  }
View Full Code Here

    messages.addAll(register.getValue());
    messages.add(process(register.getKey(), account));
  }

  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

TOP

Related Classes of org.internna.ossmoney.model.qif.Message

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.