Package net.sourceforge.wampum.system.data

Examples of net.sourceforge.wampum.system.data.DAOFactory


  public GnuCashHandler(GNUCashEventListener eventListener) {
    this.eventListener = eventListener;
  }

  public void startDocument() throws SAXException {
    daoFactory = new DAOFactory();
  }
View Full Code Here


 
  public void endTag(String tagName) {
    if (tagName.equalsIgnoreCase("STMTTRN")) {
      System.out.println(name + "  " + amount + "  " + dateFormat.format(datePosted.getTime()));
      Transaction trans = null;
      DAOFactory factory = new DAOFactory();
     
      try {
        factory.beginTransaction();
        // Look for fitID
        if (this.fitID != null) {
          RegisterDAO registerDAO = (RegisterDAO)factory.getDAO("register");
          trans = registerDAO.loadTransactionByFitID(this.fitID);
          System.out.println("Transaction found!");
        }
     
        if (trans == null) {
          trans = new Transaction();
          Payee payee = PayeeUtils.findPayee(this.name, true);
          trans.setPayee(payee);
          trans.setDatePosted(datePosted);
          trans.setFitID(fitID);
       
          Transaction payeeTrans = PayeeUtils.findLastTransactionForPayee(payee, this.accountID);
          if (payeeTrans != null) {
            List transSplitList = payeeTrans.getTransSplitList();
            TransSplit transSplit = null;
            TransSplit newSplit = null;
            double oldTotal = 0;
            for (int i=0; i<transSplitList.size(); i++) {
              transSplit = (TransSplit)transSplitList.get(i);
              if (transSplit.getAmount().doubleValue() >= 0)
                oldTotal += transSplit.getAmount().doubleValue();
            }
         
            for (int i=0; i<transSplitList.size(); i++) {
              transSplit = (TransSplit)transSplitList.get(i);
              newSplit = new TransSplit();
              newSplit.setParentTransaction(trans);
              newSplit.setAccount(transSplit.getAccount());
              double splitAmount = Math.abs((transSplit.getAmount().doubleValue()/oldTotal)*amount);
              if (newSplit.getAccountAccountID().equals(accountID)) {
                if (amount >= 0) {
                  newSplit.setAmount(new Double(splitAmount));
                }
                else {
                  newSplit.setAmount(new Double(-splitAmount));
                }
              }
              else {
                if (amount >= 0) {
                  newSplit.setAmount(new Double(-splitAmount));
                }
                else {
                  newSplit.setAmount(new Double(splitAmount));
                }
              }
              trans.appendTransSplit(newSplit);
            }
          }
          else {
            AccountDAO accountDAO = (AccountDAO)factory.getDAO("account");
            Account newAccount = (Account)accountDAO.load("WHERE TITLE = 'Imbalance-USD'", null, true).get(0);
            TransSplit transSplit = new TransSplit();
            transSplit.setParentTransaction(trans);
            Account account = new Account();
            account.setAccountID(accountID);
            transSplit.setAccount(account);
            transSplit.setAmount(new Double(amount));
            trans.appendTransSplit(transSplit);
         
            TransSplit newSplit = new TransSplit();
            newSplit.setParentTransaction(trans);
            newSplit.setAccount(newAccount);
            newSplit.setAmount(new Double(-amount));
            trans.appendTransSplit(newSplit);
          }
        }
        TransactionDAO transDAO = (TransactionDAO)factory.getDAO("transaction");
        transDAO.store(trans, true);
        factory.commit();
        factory.close();
      }
      catch (Exception ex) {
        System.out.println("Error with transaction: Payee" + trans.getPayee().getName() + "\n" +
            "Fit ID: " + trans.getFitID());
        throw new RuntimeException(ex);
View Full Code Here

 
  private void buildPayeesTree() {
      DefaultMutableTreeNode root = new DefaultMutableTreeNode("Payees");
    DefaultTreeModel treeModel = new DefaultTreeModel(root);
   
    DAOFactory daoFactory = new DAOFactory();
    PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
    payeeList = payeeDao.load(null, "ORDER BY NAME", true);

    GUIPayee treePayee = null;
    DefaultMutableTreeNode treeNode = null;
    for (int i=0; i<payeeList.size(); i++) {
View Full Code Here

  }
 
  private static String[] columnNames = {"Date", "Deposit Accounts", "Withdraw Accounts", "Amount"};
  private void updateRegisterTableData() {
    if (currentPayee != null) {
      DAOFactory daoFactory = new DAOFactory();
      RegisterDAO registerDao = (RegisterDAO)daoFactory.getDAO("register");
      transactionList = registerDao.loadTransactionsForPayee(currentPayee.getPayeeID());
    }
   
    TableModel dataModel = new AbstractTableModel() {
      private static final long serialVersionUID = 1;
View Full Code Here

  public void actionPerformed(ActionEvent e) {
    if ("saveButton".equals(e.getActionCommand())) {
      currentPayee.setName(name.getText());
      currentPayee.setFilters(filters.getText());
      currentPayee.setActive(new Boolean(true));
      DAOFactory daoFactory = new DAOFactory();
      PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
      payeeDao.store(currentPayee, false);
      buildPayeesTree();
      buildPayeeDropDown();
      checkButtonStatus();
    }
    else if ("clearButton".equals(e.getActionCommand())) {
        currentPayee = new Payee();
        name.setText(currentPayee.getName());
        filters.setText(currentPayee.getFilters());
        updateRegisterTableData();
        checkButtonStatus();
    }
    else if ("deleteButton".equals(e.getActionCommand())) {
      DAOFactory daoFactory = new DAOFactory();
      PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
      currentPayee.setActive(new Boolean(false));
      payeeDao.delete(currentPayee);
     
        currentPayee = new Payee();
        name.setText(currentPayee.getName());
View Full Code Here

public abstract class Controller {

  protected DAOFactory daoFactory = null;
 
  public Controller() {
    daoFactory = new DAOFactory();
  }
View Full Code Here

      };
      chooser.setFileFilter(filter);
      int returnVal = chooser.showSaveDialog(Main.mainFrame);
      if(returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          DAOFactory daoFactory = new DAOFactory();
          PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
          List payeeList = payeeDao.load(null, "ORDER BY NAME", true);
         
          File file = chooser.getSelectedFile();
          FileWriter fileWriter = new FileWriter(file);
         
View Full Code Here

         
          // build xml
          Document doc = XMLUtil.newDocument("Wampum");
          Element payeesElement = XMLUtil.newChildElement(doc.getDocumentElement(), "Payees", null);
         
          DAOFactory daoFactory = new DAOFactory();
          PayeeDAO payeeDAO = (PayeeDAO)daoFactory.getDAO("payee");
          List payees = payeeDAO.load("", "ORDER BY NAME", true);
          Payee payee = null;
          for (int i=0; i<payees.size(); i++) {
            payee = (Payee)payees.get(i);
            XMLUtil.appendChildNode(payeesElement, PayeeXML.createXMLDocument(payee).getDocumentElement());
          }
         
          Element accountsElement = XMLUtil.newChildElement(doc.getDocumentElement(), "Accounts", null);
          AccountDAO accountDAO = (AccountDAO)daoFactory.getDAO("account");
          List accounts = accountDAO.load(null, "ORDER BY TITLE", false);
          Account account = null;
          for (int i=0; i<accounts.size(); i++) {
            account = (Account)accounts.get(i);
            account.setAccountList(new ArrayList());
            XMLUtil.appendChildNode(accountsElement, AccountXML.createXMLDocument(account).getDocumentElement());
          }
         
          Element transElement = XMLUtil.newChildElement(doc.getDocumentElement(), "Transactions", null);
          TransactionDAO transDAO = (TransactionDAO)daoFactory.getDAO("transaction");
          List transList = transDAO.load(null, null, false);
          Transaction trans = null;
          for (int i=0; i<transList.size(); i++) {
            trans = (Transaction)transList.get(i);
            List transSplitList = trans.getTransSplitList();
View Full Code Here

      chooser.setFileFilter(filter);
     
      int returnVal = chooser.showOpenDialog(Main.mainFrame);
      if(returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          DAOFactory daoFactory = new DAOFactory();
          PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
          List payeeList = payeeDao.load(null, "ORDER BY NAME", true);
         
          File file = chooser.getSelectedFile();
          BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
          String line = null;
View Full Code Here

TOP

Related Classes of net.sourceforge.wampum.system.data.DAOFactory

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.