Ejemplo n.º 1
0
  public List getPortfolio() {
    List result = new ArrayList();

    Map map = new HashMap();
    for (Iterator iter2 = getTransactions().iterator(); iter2.hasNext(); ) {
      Transaction transaction = (Transaction) iter2.next();
      PortfolioPosition position = (PortfolioPosition) map.get(transaction.getSecurity());
      if (position == null)
        map.put(
            transaction.getSecurity(),
            new PortfolioPosition(
                this,
                transaction.getSecurity(),
                transaction.getQuantity(),
                transaction.getAmount()));
      else position.add(transaction.getQuantity(), transaction.getAmount());
    }

    List list = new ArrayList(map.keySet());
    Collections.sort(
        list,
        new Comparator() {
          public int compare(Object arg0, Object arg1) {
            return ((Security) arg0).getDescription().compareTo(((Security) arg1).getDescription());
          }
        });
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
      Security security = (Security) iter.next();
      PortfolioPosition position = (PortfolioPosition) map.get(security);
      if (position.getQuantity() != 0) result.add(position);
    }

    return result;
  }
Ejemplo n.º 2
0
  public void update() {
    infoPanel.update();

    Object[][] history = new Object[account.getHistory().size()][5];
    int i = 0;
    for (Transaction t : account.getHistory()) {
      history[i][0] = t.getType();
      BigDecimal amount;
      BigDecimal balance;
      if (account.getType().isLoan()) {
        amount = (t.getType().isPositive() ? t.getAmount().negate() : t.getAmount());
        balance = t.getBalance().negate();
      } else {
        amount = (t.getType().isPositive() ? t.getAmount() : t.getAmount().negate());
        balance = t.getBalance();
      }
      history[i][1] = FORMATTER.valueToString(amount);
      history[i][2] = FORMATTER.valueToString(balance);
      history[i][3] = t.getTimestamp();
      history[i][4] = t.getFraudStatus();
      i++;
    }
    historyTable.setModel(
        new javax.swing.table.DefaultTableModel(
            history, new String[] {"Type", "Amount", "Balance", "Month", "Flag"}) {
          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
          }
        });
    historyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    historyTable.revalidate();
  }
Ejemplo n.º 3
0
 void transact(LinkedList<Transaction> transactions) {
   for (Transaction t : transactions) {
     Player p = getServer().getPlayer(t.getName());
     if (p != null) {
       getBank().give(p, t.getAmount(), t.getType());
     }
   }
 }
Ejemplo n.º 4
0
  public PortfolioPosition getPortfolio(Security security) {
    PortfolioPosition position = new PortfolioPosition(this, security, 0, 0);

    for (Iterator iter2 = getTransactions().iterator(); iter2.hasNext(); ) {
      Transaction transaction = (Transaction) iter2.next();
      if (position.getSecurity().equals(transaction.getSecurity()))
        position.add(transaction.getQuantity(), transaction.getAmount());
    }

    return position;
  }
Ejemplo n.º 5
0
 @Override
 public JsonElement serialize(
     Transaction transaction, Type type, JsonSerializationContext jsonSerializationContext) {
   final JsonObject jo = new JsonObject();
   jo.addProperty("amount", transaction.getAmount());
   jo.addProperty("type", transaction.getType());
   if (transaction.getParent() != null) {
     jo.addProperty("parent", transaction.getParent().getId());
   }
   return jo;
 }
Ejemplo n.º 6
0
  private void newTransaction(final Transaction t) {
    clearForm();

    amountField.setDecimal(t.getAmount(accountProperty().get()));

    memoTextField.setText(t.getMemo());
    payeeTextField.setText(t.getPayee());
    numberComboBox.setValue(t.getNumber());

    datePicker.setValue(t.getLocalDate());
    setReconciledState(t.getReconciled(accountProperty().get()));
  }
 private static void writeTransactionsFile(RandomAccessFile out, ArrayList<Transaction> list)
     throws IOException {
   out.seek(0);
   for (int i = 0; i < list.size(); i++) {
     Transaction t = list.get(i);
     out.write(("" + t.getBuyOrSell() + "\n").getBytes());
     out.write(("" + t.getShareholderId() + "\n").getBytes());
     out.write((t.getCompanySymbol() + "\n").getBytes());
     out.write(("" + t.getAmount() + "\n").getBytes());
     out.write(("" + t.getPrice() + "\n").getBytes());
     out.write((DataHandler.dateFormat.format(t.getDate()) + "\n").getBytes());
   }
 }
Ejemplo n.º 8
0
  /**
   * Writes one bank transaction
   *
   * @param transaction <code>Transaction</code> to write
   */
  private void writeBankTransaction(final Transaction transaction) {
    indentedWriter.println(wrapOpen(STMTTRN), indentLevel++);
    indentedWriter.println(
        wrapOpen(TRNTYPE)
            + (transaction.getAmount(account).compareTo(BigDecimal.ZERO) == 1 ? CREDIT : DEBIT),
        indentLevel);

    indentedWriter.println(wrapOpen(DTPOSTED) + encodeDate(transaction.getDate()), indentLevel);
    indentedWriter.println(
        wrapOpen(TRNAMT) + transaction.getAmount(account).toPlainString(), indentLevel);
    indentedWriter.println(wrapOpen(REFNUM) + transaction.getUuid(), indentLevel);
    indentedWriter.println(wrapOpen(NAME) + transaction.getPayee(), indentLevel);
    indentedWriter.println(wrapOpen(MEMO) + transaction.getMemo(), indentLevel);

    // write the check number if applicable
    if (account.getAccountType() == AccountType.CHECKING && !transaction.getNumber().isEmpty()) {
      indentedWriter.println(wrapOpen(CHECKNUM) + transaction.getNumber(), indentLevel);
    }

    // write out the banks transaction id if previously imported
    writeFitID(transaction);

    indentedWriter.println(wrapClose(STMTTRN), --indentLevel);
  }
Ejemplo n.º 9
0
 public static void createTransaction(Transaction transaction) throws ParseException {
   try {
     String query =
         "insert into transaction_table(business_id, transaction_id, type, category, description, amount, transaction_date, account_balance) values (?,?,?,?,?,?,?,?)";
     PreparedStatement preparedStatement = connection.prepareStatement(query);
     preparedStatement.setInt(1, 1);
     preparedStatement.setInt(2, transaction.getId());
     preparedStatement.setBoolean(3, transaction.getType());
     preparedStatement.setString(4, transaction.getCategory());
     preparedStatement.setString(5, transaction.getDescription());
     preparedStatement.setFloat(6, transaction.getAmount());
     preparedStatement.setString(7, transaction.getTransactionDate());
     preparedStatement.setFloat(8, transaction.getAccountBalance());
     preparedStatement.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 10
0
 public static void updateTransaction(Transaction transaction) throws ParseException {
   try {
     String query =
         "update transaction_table set type=?, category=?, description=?, amount=?, transaction_date=?, account_balance=? where transaction_id=?";
     PreparedStatement preparedStatement = connection.prepareStatement(query);
     preparedStatement.setInt(1, 1);
     preparedStatement.setInt(2, transaction.getId());
     preparedStatement.setBoolean(3, transaction.getType());
     preparedStatement.setString(4, transaction.getCategory());
     preparedStatement.setString(5, transaction.getDescription());
     preparedStatement.setFloat(6, transaction.getAmount());
     preparedStatement.setString(7, transaction.getTransactionDate());
     preparedStatement.setFloat(8, transaction.getAccountBalance());
     preparedStatement.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 11
0
  /**
   * Gets the balance of the account
   *
   * @return the account's balance
   */
  public double getBalance() {
    double result = getInitialBalance();

    Object[] objs = getTransactions().toArray();
    for (int i = 0; i < objs.length; i++) {
      Transaction transaction = (Transaction) objs[i];
      double amount = transaction.getAmount();
      if (getCurrency() != null && !getCurrency().equals(transaction.getSecurity().getCurrency()))
        amount =
            CurrencyConverter.getInstance()
                .convert(
                    transaction.getDate(),
                    amount,
                    transaction.getSecurity().getCurrency(),
                    getCurrency());
      result += amount;
    }

    return result;
  }
Ejemplo n.º 12
0
  private static double generateItemTotal(int itemID, boolean bought, boolean sold) {
    double amount = 0;
    List<Transaction> list;
    if (bought)
      list =
          ChestShop.getDB()
              .find(Transaction.class)
              .where()
              .eq("buy", 1)
              .eq("itemID", itemID)
              .findList();
    else if (sold)
      list =
          ChestShop.getDB()
              .find(Transaction.class)
              .where()
              .eq("buy", 0)
              .eq("itemID", itemID)
              .findList();
    else list = ChestShop.getDB().find(Transaction.class).where().eq("itemID", itemID).findList();

    for (Transaction t : list) amount += t.getAmount();
    return amount;
  }
Ejemplo n.º 13
0
  public static void ExportPortfolios() throws FileNotFoundException, UnsupportedEncodingException {
    String filename = "xp.txt";
    Iterator it = users.entrySet().iterator();
    PrintWriter writer = new PrintWriter(filename, "UTF-8");
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();

      writer.print(pair.getKey() + "|" + encrypt((String) pair.getValue()));
      writer.print("|");
      Portfolio p = portfolios.get(pair.getKey());
      Map<String, Integer> equitiess = p.getEquities();
      Iterator it1 = equitiess.entrySet().iterator();
      while (it1.hasNext()) {
        Map.Entry e = (Map.Entry) it1.next();
        writer.print("e," + e.getKey() + "," + e.getValue() + "|");
      }
      Map<String, Account> accountss = p.getAccounts();
      Iterator it2 = accountss.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry a = (Map.Entry) it2.next();
        Date d = ((Account) a.getValue()).getDateAdded();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
        String da = sdf.format(d);
        writer.print(
            "a,"
                + ((Account) a.getValue()).getType()
                + ","
                + ((Account) a.getValue()).getName()
                + ","
                + (((Account) a.getValue()).getInitialAmount()
                    + ","
                    + (((Account) a.getValue()).getCurrentAmount())
                    + ","
                    + da
                    + "|"));
      }
      for (Transaction tr : p.getTrans()) {
        if (tr.getType().equals("t")) {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              "t," + tr.getA1() + "," + tr.getA2() + "," + tr.getAmount() + "," + da + "|");
        } else {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              tr.getType()
                  + ","
                  + tr.getEquity().getTicker()
                  + ","
                  + tr.getNumber()
                  + ","
                  + tr.getA1()
                  + da
                  + "|");
        }
      }
      writer.println();
    }
    writer.close();
  }