UserInterface.FinanceRole.TransferToRegSiteJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.FinanceRole.TransferToRegSiteJPanel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UserInterface.FinanceRole;

import Business.CountryEnterprise.CountryEnterprise;
import Business.CountryEnterprise.RegSiteEnterprise.RegisteredSiteEnterprise;
import Business.Helper.AutoTransfer;
import Business.Helper.CardLayoutContainer;
import Business.Helper.GenerateReports;
import Business.Helper.Validation;
import Business.Organization.Organization;
import Business.Organization.WorldAdminOrganization;
import Business.Transaction.Transaction;
import Business.UserAccount.UserAccount;
import Business.WorldEnterprise;
import java.awt.BorderLayout;
import java.awt.Color;
import java.math.BigDecimal;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author "Smit Shah, NUID: 001748537, AED - Final Project"
 */
public class TransferToRegSiteJPanel extends javax.swing.JPanel {

    /**
     * Creates new form TransferToRegSiteJPanel
     */
    private JPanel userProcessContainer;
    private UserAccount objUserAccount;
    private WorldEnterprise objWorldEnterprise;
    private Organization objOrganization;
    private BigDecimal autoDonationAmount, individualDonationAmount;

    public TransferToRegSiteJPanel(JPanel userProcessContainerPassed, UserAccount objUserAccountPassed,
            WorldEnterprise objWorldEnterprisePassed, Organization objOrganizationPassed) {
        initComponents();

        this.userProcessContainer = userProcessContainerPassed;
        this.objUserAccount = objUserAccountPassed;
        this.objWorldEnterprise = objWorldEnterprisePassed;
        this.objOrganization = objOrganizationPassed;

        populateCountryComboBox();
        populateLowRegSiteTable();

        if (objOrganizationPassed instanceof WorldAdminOrganization) {
            dollarJLabel.setVisible(false);
            autoTransferJButton.setVisible(false);
            autoTransferJTextField.setVisible(false);
            donateAmountJLabel.setVisible(false);
            donationAmountJTextField.setVisible(false);
            donateJButton.setVisible(false);
        } else {
            dollarJLabel.setVisible(true);
            autoTransferJButton.setVisible(true);
            autoTransferJTextField.setVisible(true);
            donateAmountJLabel.setVisible(true);
            donationAmountJTextField.setVisible(true);
            donateJButton.setVisible(true);
        }
    }

    private void populateCountryComboBox() {

        countryJComboBox.removeAllItems();

        for (CountryEnterprise objCountryEnterprise : objWorldEnterprise.getObjCountryEnterpriseDirectory()
                .getCountryEnterpriseList()) {
            countryJComboBox.addItem(objCountryEnterprise);
        }
    }

    private void populateRegSiteTable(CountryEnterprise objCountryEnterprise) {

        DefaultTableModel dtm = (DefaultTableModel) regSiteJTable.getModel();
        dtm.setRowCount(0);

        for (RegisteredSiteEnterprise objRegisteredSiteEnterprise : objCountryEnterprise
                .getObjRegisteredSiteDirectory().getRegisteredSiteList()) {

            Object row[] = new Object[2];
            row[0] = objRegisteredSiteEnterprise.getOrganizationID();
            row[1] = objRegisteredSiteEnterprise;

            dtm.addRow(row);

        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        donationAmountJTextField = new javax.swing.JTextField();
        backJButton4 = new javax.swing.JButton();
        titleJLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        regSiteJTable = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        transationHistoryJTable = new javax.swing.JTable();
        donateJButton = new javax.swing.JButton();
        title2JLabel = new javax.swing.JLabel();
        donateAmountJLabel = new javax.swing.JLabel();
        countryJLabel = new javax.swing.JLabel();
        countryJComboBox = new javax.swing.JComboBox();
        autoTransferJButton = new javax.swing.JButton();
        autoTransferJTextField = new javax.swing.JTextField();
        transferDetailsJPanel = new javax.swing.JPanel();
        dollarJLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane3 = new javax.swing.JScrollPane();
        lowRegJTable = new javax.swing.JTable();
        countryJLabel1 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        donationAmountJTextField.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N

        backJButton4.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        backJButton4.setText("<< Back");
        backJButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButton4ActionPerformed(evt);
            }
        });

        titleJLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        titleJLabel.setText("Transfer to Reistered Site");

        regSiteJTable.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        regSiteJTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "ID", "Name" }) {
            boolean[] canEdit = new boolean[] { false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        regSiteJTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                regSiteJTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(regSiteJTable);
        if (regSiteJTable.getColumnModel().getColumnCount() > 0) {
            regSiteJTable.getColumnModel().getColumn(0).setResizable(false);
            regSiteJTable.getColumnModel().getColumn(1).setResizable(false);
        }

        transationHistoryJTable.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        transationHistoryJTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Transaction ID", "Amount", "Date" }) {
            boolean[] canEdit = new boolean[] { false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane2.setViewportView(transationHistoryJTable);

        donateJButton.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        donateJButton.setText("Transfer");
        donateJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                donateJButtonActionPerformed(evt);
            }
        });

        title2JLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        title2JLabel.setText("Donation History");

        donateAmountJLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        donateAmountJLabel.setText("Transfer Amount");

        countryJLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        countryJLabel.setText("Select Country:");

        countryJComboBox.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        countryJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                countryJComboBoxActionPerformed(evt);
            }
        });

        autoTransferJButton.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        autoTransferJButton.setText("One touch Auto-Transfer");
        autoTransferJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoTransferJButtonActionPerformed(evt);
            }
        });

        autoTransferJTextField.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N

        javax.swing.GroupLayout transferDetailsJPanelLayout = new javax.swing.GroupLayout(transferDetailsJPanel);
        transferDetailsJPanel.setLayout(transferDetailsJPanelLayout);
        transferDetailsJPanelLayout.setHorizontalGroup(transferDetailsJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        transferDetailsJPanelLayout.setVerticalGroup(transferDetailsJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 200, Short.MAX_VALUE));

        dollarJLabel.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        dollarJLabel.setText("$");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        lowRegJTable.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lowRegJTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "ID", "Name", "Country", "Balance" }) {
            boolean[] canEdit = new boolean[] { false, false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        lowRegJTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lowRegJTableMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(lowRegJTable);
        if (lowRegJTable.getColumnModel().getColumnCount() > 0) {
            lowRegJTable.getColumnModel().getColumn(0).setResizable(false);
            lowRegJTable.getColumnModel().getColumn(1).setResizable(false);
            lowRegJTable.getColumnModel().getColumn(2).setResizable(false);
            lowRegJTable.getColumnModel().getColumn(3).setResizable(false);
        }

        countryJLabel1.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        countryJLabel1.setText("Registered Site with Low Balance");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(236, 236, 236).addComponent(dollarJLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(donationAmountJTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 114,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(donateJButton))
                                        .addGroup(layout.createSequentialGroup().addGap(64, 64, 64)
                                                .addComponent(donateAmountJLabel))))
                        .addGroup(layout.createSequentialGroup().addGap(321, 321, 321).addComponent(title2JLabel))
                        .addGroup(layout.createSequentialGroup().addGap(24, 24, 24).addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(backJButton4)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 655,
                                        Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup()
                                                .addComponent(autoTransferJTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 97,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18).addComponent(autoTransferJButton))
                                .addComponent(jScrollPane1)
                                .addComponent(transferDetailsJPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(titleJLabel).addComponent(countryJLabel))
                                                .addGap(18, 18, 18).addComponent(countryJComboBox,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 199,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(52, 52, 52)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 553,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addGap(158, 158, 158)
                                        .addComponent(countryJLabel1)))
                        .addContainerGap(105, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap().addComponent(titleJLabel).addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(countryJLabel).addComponent(countryJComboBox,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(autoTransferJButton).addComponent(autoTransferJTextField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18).addComponent(donateAmountJLabel).addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(donateJButton)
                                .addComponent(donationAmountJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(dollarJLabel))
                        .addGap(18, 18, 18).addComponent(title2JLabel).addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 172,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(transferDetailsJPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(backJButton4).addContainerGap(27, Short.MAX_VALUE))
                .addComponent(jSeparator1)
                .addGroup(layout.createSequentialGroup().addGap(56, 56, 56).addComponent(countryJLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 155,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void backJButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButton4ActionPerformed

        CardLayoutContainer.removeCurrentCardLayout(userProcessContainer, this);
    }//GEN-LAST:event_backJButton4ActionPerformed

    private void regSiteJTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_regSiteJTableMouseClicked

        RegisteredSiteEnterprise objRegisteredSiteEnterprise = null;

        int selectedRegSite = regSiteJTable.getSelectedRow();

        if (selectedRegSite < 0) {
            JOptionPane.showMessageDialog(null, "Please select a Site");
            return;
        }

        objRegisteredSiteEnterprise = (RegisteredSiteEnterprise) regSiteJTable.getValueAt(selectedRegSite, 1);

        if (objRegisteredSiteEnterprise != null) {

            populateTransactionTable(objRegisteredSiteEnterprise);
        } else {
            JOptionPane.showMessageDialog(null, "Please select again");
        }

    }//GEN-LAST:event_regSiteJTableMouseClicked

    private void populateLowRegSiteTable() {

        //Table
        DefaultTableModel dtm = (DefaultTableModel) lowRegJTable.getModel();
        dtm.setRowCount(0);

        for (CountryEnterprise objCountryEnterprise : objWorldEnterprise.getObjCountryEnterpriseDirectory()
                .getCountryEnterpriseList()) {
            for (RegisteredSiteEnterprise objRegisteredSiteEnterprise : objCountryEnterprise
                    .getObjRegisteredSiteDirectory().getRegisteredSiteList()) {

                objRegisteredSiteEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                BigDecimal availableBalance = objRegisteredSiteEnterprise.getObjTransactionDirectory()
                        .getAvailableRealBalance();
                int compare = availableBalance.compareTo(new BigDecimal(1000));

                if (compare < 1) {
                    Object row[] = new Object[4];
                    row[0] = objRegisteredSiteEnterprise.getOrganizationID();
                    row[1] = objRegisteredSiteEnterprise.getRegSiteName();
                    row[2] = objCountryEnterprise;
                    row[3] = "$ "
                            + objRegisteredSiteEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

                    dtm.addRow(row);
                }
            }
        }
    }

    private void populateTransactionTable(RegisteredSiteEnterprise objRegisteredSiteEnterprise) {

        //Chart        
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        //Table
        DefaultTableModel dtm = (DefaultTableModel) transationHistoryJTable.getModel();
        dtm.setRowCount(0);

        if (objRegisteredSiteEnterprise != null) {
            for (Transaction objTransaction : objRegisteredSiteEnterprise.getObjTransactionDirectory()
                    .getTransactionList()) {

                if (objTransaction.getTransactionSource()
                        .equals(Transaction.TransactionSourceType.FromWorldEnterprise.getValue())) {

                    Object row[] = new Object[3];
                    row[0] = objTransaction;
                    row[1] = "$ " + objTransaction.getTransactionBDAmount();
                    row[2] = objTransaction.getTransactionDateToDisplay();

                    dtm.addRow(row);

                    dataSet.setValue(objTransaction.getTransactionBDAmount(), "Amount",
                            objTransaction.getTransactionDateToDisplay());
                }
            }

            JFreeChart chart = ChartFactory.createBarChart3D("Overview of entire Transaction", "Transaction Date",
                    "Amount in USD $", dataSet, PlotOrientation.VERTICAL, false, true, false);

            CategoryPlot plot = chart.getCategoryPlot();
            plot.setRangeGridlinePaint(Color.black);

            ChartPanel myChart = new ChartPanel(chart);
            transferDetailsJPanel.setLayout(new java.awt.BorderLayout());
            transferDetailsJPanel.add(myChart, BorderLayout.CENTER);
            transferDetailsJPanel.validate();
            transferDetailsJPanel.setVisible(true);
        } else {
            transferDetailsJPanel.setVisible(false);
        }
    }

    private void donateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_donateJButtonActionPerformed

        //Validation
        boolean validationSuccess;
        validationSuccess = validationIndividualTansfer();

        if (validationSuccess) {

            RegisteredSiteEnterprise objRegisteredSiteEnterprise = null;

            int selectedRegSite = regSiteJTable.getSelectedRow();

            if (selectedRegSite < 0) {
                JOptionPane.showMessageDialog(null, "Please select a Site");
                return;
            }

            objRegisteredSiteEnterprise = (RegisteredSiteEnterprise) regSiteJTable.getValueAt(selectedRegSite, 1);

            if (objRegisteredSiteEnterprise != null) {

                objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                BigDecimal worldBalance = objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

                int positiveWorldBalance = worldBalance.compareTo(individualDonationAmount);

                if (positiveWorldBalance >= 1) {

                    int response = JOptionPane.showConfirmDialog(null,
                            "Total transfer of $ " + individualDonationAmount + "/- Do you want to transfer?",
                            "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                    if (response == JOptionPane.YES_OPTION) {

                        //Registered Site Transaction
                        Transaction objRealRSTransaction = (Transaction) objRegisteredSiteEnterprise
                                .getObjTransactionDirectory().addNewTransaction();
                        objRealRSTransaction.setTransactionBDAmount(individualDonationAmount);
                        objRealRSTransaction.setObjUserAccountSource(objUserAccount);
                        objRealRSTransaction.setObjUserAccountDestination(null);
                        objRealRSTransaction.setTransactionSource(
                                Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                        objRealRSTransaction.setTransactionDestination(
                                Transaction.TransactionSourceType.ToRegSiteEnterprise.getValue());
                        objRealRSTransaction.setTransactionType(Transaction.TransactionType.Credit.getValue());
                        objRealRSTransaction.setTransactionMode(Transaction.TransactionModeType.Real.getValue());
                        objRegisteredSiteEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                        //WorldEnterprise Transaction
                        Transaction objRealWETransaction = (Transaction) objWorldEnterprise
                                .getObjTransactionDirectory().addNewTransaction();
                        objRealWETransaction.setTransactionBDAmount(individualDonationAmount);
                        objRealWETransaction.setObjUserAccountSource(objUserAccount);
                        objRealWETransaction.setObjUserAccountDestination(null);
                        objRealWETransaction.setTransactionSource(
                                Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                        objRealWETransaction.setTransactionDestination(
                                Transaction.TransactionSourceType.ToRegSiteEnterprise.getValue());
                        objRealWETransaction.setTransactionType(Transaction.TransactionType.Debit.getValue());
                        objRealWETransaction.setTransactionMode(Transaction.TransactionModeType.Real.getValue());
                        objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                        populateTransactionTable(objRegisteredSiteEnterprise);

                        JOptionPane.showMessageDialog(null,
                                "$ " + individualDonationAmount + "/- transferred successfully");

                        donationAmountJTextField.setText(null);
                        populateLowRegSiteTable();

                        //RegSiteTransferRecords
                        String donationLogs = objRealWETransaction.getTransactionID() + ","
                                + objRealWETransaction.getTransactionBDAmount() + ","
                                + objRealWETransaction.getObjUserAccountSource() + ","
                                + objRealWETransaction.getTransactionSource() + "," + objRegisteredSiteEnterprise
                                + "," + objRealWETransaction.getTransactionDestination() + ","
                                + objRealWETransaction.getTransactionType() + ","
                                + objRealWETransaction.getTransactionMode();

                        GenerateReports.regSiteTransferRecords(donationLogs);
                    }

                } else {
                    JOptionPane.showMessageDialog(null, "World Balance is low");
                }
            } else {
                JOptionPane.showMessageDialog(null, "Please select again");
            }
        }
    }//GEN-LAST:event_donateJButtonActionPerformed

    private boolean validationIndividualTansfer() {

        String individualDonation = donationAmountJTextField.getText().trim();

        if (Validation.checkForNull(individualDonation)) {

            JOptionPane.showMessageDialog(null, "Please enter a amount");
            donationAmountJTextField.requestFocus();
            return false;
        }

        try {
            individualDonationAmount = new BigDecimal(individualDonation);

            if (Validation.checkForNegativeAmount(individualDonationAmount)) {

                JOptionPane.showMessageDialog(null, "Please enter a positive amount");
                donationAmountJTextField.requestFocus();
                return false;
            }

            if (individualDonationAmount.scale() > 2) {
                JOptionPane.showMessageDialog(null, "Please enter a proper amount with only 2 decimal. eg. 108.18");
                donationAmountJTextField.requestFocus();
                return false;
            }

            return true;

        } catch (NumberFormatException exe) {
            JOptionPane.showMessageDialog(null, "Please enter a proper amount");
            donationAmountJTextField.requestFocus();
            return false;
        }
    }

    private void countryJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_countryJComboBoxActionPerformed

        CountryEnterprise objCountryEnterprise = (CountryEnterprise) countryJComboBox.getSelectedItem();

        if (objCountryEnterprise != null) {
            populateRegSiteTable(objCountryEnterprise);
            populateTransactionTable(null);
        }
    }//GEN-LAST:event_countryJComboBoxActionPerformed

    private void autoTransferJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoTransferJButtonActionPerformed

        //Validation
        boolean validationSuccess;
        validationSuccess = validationAutoTansfer();

        if (validationSuccess) {

            objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

            BigDecimal worldDonation = AutoTransfer.transferCheck(objWorldEnterprise, objUserAccount,
                    autoDonationAmount);
            BigDecimal worldBalance = objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance();
            System.out.println(worldDonation);

            System.out.println(objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance());
            System.out.println(objWorldEnterprise.getObjTransactionDirectory().getAvailableVirtualBalance());

            int positiveWorldBalance = worldBalance.compareTo(worldDonation);

            if (positiveWorldBalance >= 1) {
                JDialog.setDefaultLookAndFeelDecorated(true);

                int response = JOptionPane.showConfirmDialog(null,
                        "Total transfer of $ " + worldDonation + "/- Do you want to transfer?", "Confirm",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.YES_OPTION) {
                    System.out.println("Yes button clicked");
                    worldDonation = AutoTransfer.transferConfirm(objWorldEnterprise, objUserAccount,
                            autoDonationAmount);

                    JOptionPane.showMessageDialog(null, "$ " + worldDonation + "/- transferred successfully");

                    autoTransferJTextField.setText(null);

                    populateLowRegSiteTable();
                }
            } else {
                JOptionPane.showMessageDialog(null, "World Balance is low");
            }
        }
    }//GEN-LAST:event_autoTransferJButtonActionPerformed

    private void lowRegJTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lowRegJTableMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_lowRegJTableMouseClicked

    private boolean validationAutoTansfer() {

        String autoDonation = autoTransferJTextField.getText().trim();

        if (Validation.checkForNull(autoDonation)) {

            JOptionPane.showMessageDialog(null, "Please enter a amount");
            autoTransferJTextField.requestFocus();
            return false;
        }

        try {
            autoDonationAmount = new BigDecimal(autoDonation);

            if (Validation.checkForNegativeAmount(autoDonationAmount)) {

                JOptionPane.showMessageDialog(null, "Please enter a positive amount");
                autoTransferJTextField.requestFocus();
                return false;
            }

            if (autoDonationAmount.scale() > 2) {
                JOptionPane.showMessageDialog(null, "Please enter a proper amount with only 2 decimal. eg. 108.18");
                autoTransferJTextField.requestFocus();
                return false;
            }

            return true;

        } catch (NumberFormatException exe) {
            JOptionPane.showMessageDialog(null, "Please enter a proper amount");
            autoTransferJTextField.requestFocus();
            return false;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton autoTransferJButton;
    private javax.swing.JTextField autoTransferJTextField;
    private javax.swing.JButton backJButton4;
    private javax.swing.JComboBox countryJComboBox;
    private javax.swing.JLabel countryJLabel;
    private javax.swing.JLabel countryJLabel1;
    private javax.swing.JLabel dollarJLabel;
    private javax.swing.JLabel donateAmountJLabel;
    private javax.swing.JButton donateJButton;
    private javax.swing.JTextField donationAmountJTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable lowRegJTable;
    private javax.swing.JTable regSiteJTable;
    private javax.swing.JLabel title2JLabel;
    private javax.swing.JLabel titleJLabel;
    private javax.swing.JTable transationHistoryJTable;
    private javax.swing.JPanel transferDetailsJPanel;
    // End of variables declaration//GEN-END:variables
}