com.openbravo.pos.customers.JCustomerPanel.java Source code

Java tutorial

Introduction

Here is the source code for com.openbravo.pos.customers.JCustomerPanel.java

Source

//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2007-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.
package com.openbravo.pos.customers;

import com.openbravo.basic.BasicException;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.forms.AppConfig;
import java.awt.Component;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSales;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

public class JCustomerPanel extends JDialog {

    int x = 300;
    int y = 101;
    int width = 620;
    int height = 530;
    protected DirtyManager m_Dirty = new DirtyManager();
    public static AppView app = null;
    private static DataLogicCustomers dlCustomers = null;
    private static DataLogicSales dlSales = null;
    private DefaultListModel model = null;
    private List<CustomerListInfo> li = null;
    String Receivable = null;
    String Advance = null;

    public static void showMessage(Component parent, AppView app) throws BasicException {

        JCustomerPanel.app = app;
        dlCustomers = (DataLogicCustomers) app.getBean("com.openbravo.pos.customers.DataLogicCustomers");
        dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales");

        Window window = getWindow(parent);
        JCustomerPanel myMsg;
        if (window instanceof Frame) {
            myMsg = new JCustomerPanel((Frame) window, true);
        } else {
            myMsg = new JCustomerPanel((Dialog) window, true);
        }
        //myMsg.applyComponentOrientation(parent.getComponentOrientation());
        myMsg.init();
    }

    private JCustomerPanel(Frame frame, boolean b) {
        super(frame, true);
        setBounds(x, y, width, height);

    }

    private JCustomerPanel(Dialog dialog, boolean b) {
        super(dialog, true);
        setBounds(x, y, width, height);

    }

    public void init() throws BasicException {

        initComponents();

        this.setTitle("Customers");
        setCustomerId();
        add(jPanel6);
        setVisible(true);

    }

    public void setCustomerObjectVals(CustomerInfoExt cinfo) {
        cinfo.setName(m_jName.getText());
        cinfo.setNotes("");
        cinfo.setSearchkey("get data from webservice");
        cinfo.setTaxid(null);
        cinfo.setVisible(true);
        cinfo.setAddress(txtAddress.getText());
        cinfo.setAddress2(txtAddress1.getText());
        cinfo.setCity(txtCity.getText());
        cinfo.setCountry(txtCountry.getText());
        cinfo.setCurdate(null);
        cinfo.setCurdebt(0.0);
        cinfo.setEmail(txtEmail.getText());
        cinfo.setFax(null);
        // cinfo.setFirstname(txtFirstName.getText());
        //cinfo.setLastname(txtLastName.getText());
        cinfo.setMaxdebt(0.0);
        cinfo.setPhone(txtPhone.getText());
        cinfo.setPhone2(null);
        cinfo.setPostal(txtPostal.getText());
        cinfo.setRegion(txtRegion.getText());
        cinfo.setCustomerId(m_jCustomerId.getText());
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        m_jName = new javax.swing.JTextField();
        m_jCustomerId = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        txtPhone = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        txtPostal = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        txtCity = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        txtRegion = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtCountry = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtAddress1 = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jbtnNew = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jbtnSave = new javax.swing.JButton();
        jbtnClose = new javax.swing.JButton();

        jLabel3.setText(AppLocal.getIntString("label.name")); // NOI18N
        jLabel3.setPreferredSize(new java.awt.Dimension(0, 25));

        m_jName.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        m_jName.setPreferredSize(new java.awt.Dimension(0, 25));

        m_jCustomerId.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        m_jCustomerId.setFocusable(false);
        m_jCustomerId.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel1.setText("Customer Id");
        jLabel1.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel16.setText(AppLocal.getIntString("label.email")); // NOI18N
        jLabel16.setPreferredSize(new java.awt.Dimension(0, 25));

        txtEmail.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtEmail.setPreferredSize(new java.awt.Dimension(0, 25));

        txtPhone.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtPhone.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel17.setText(AppLocal.getIntString("label.phone")); // NOI18N
        jLabel17.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel22.setText(AppLocal.getIntString("label.postal")); // NOI18N
        jLabel22.setPreferredSize(new java.awt.Dimension(0, 25));

        txtPostal.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtPostal.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel23.setText(AppLocal.getIntString("label.city")); // NOI18N
        jLabel23.setPreferredSize(new java.awt.Dimension(0, 25));

        txtCity.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtCity.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel24.setText(AppLocal.getIntString("label.region")); // NOI18N
        jLabel24.setPreferredSize(new java.awt.Dimension(0, 25));

        txtRegion.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtRegion.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel20.setText(AppLocal.getIntString("label.country")); // NOI18N
        jLabel20.setPreferredSize(new java.awt.Dimension(0, 25));

        txtCountry.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtCountry.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel2.setText("Address 1");
        jLabel2.setPreferredSize(new java.awt.Dimension(0, 25));

        txtAddress.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtAddress.setPreferredSize(new java.awt.Dimension(0, 25));

        jLabel4.setText("Address 2");
        jLabel4.setPreferredSize(new java.awt.Dimension(0, 25));

        txtAddress1.setBorder(javax.swing.BorderFactory
                .createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")));
        txtAddress1.setPreferredSize(new java.awt.Dimension(0, 25));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(104, 104, 104)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel17,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel16,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                .add(jLabel22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtRegion,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtCity,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(txtCountry, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(txtPostal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtPhone,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtEmail,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtAddress,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, txtAddress1,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, m_jCustomerId,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, m_jName,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE))
                        .add(155, 155, 155)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup().add(27, 27, 27)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel3,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .add(jPanel1Layout.createSequentialGroup()
                                        .add(m_jCustomerId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(7, 7, 7).add(m_jName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtPhone, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(7, 7, 7)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtEmail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtAddress1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(jPanel1Layout.createSequentialGroup()
                                        .add(txtPostal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(txtCity,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jLabel23, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtRegion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(txtCountry, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabel20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(42, 42, 42)));

        jbtnNew.setBackground(new java.awt.Color(255, 255, 255));
        jbtnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/editnew.png"))); // NOI18N
        jbtnNew.setMnemonic('n');
        jbtnNew.setToolTipText("New");
        jbtnNew.setFocusPainted(false);
        jbtnNew.setFocusable(false);
        jbtnNew.setMargin(new java.awt.Insets(2, 8, 2, 8));
        jbtnNew.setRequestFocusEnabled(false);
        jbtnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNewActionPerformed(evt);
            }
        });

        jbtnSave.setBackground(new java.awt.Color(255, 255, 255));
        jbtnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/filesave.png"))); // NOI18N
        jbtnSave.setMnemonic('s');
        jbtnSave.setToolTipText("Save");
        jbtnSave.setFocusPainted(false);
        jbtnSave.setFocusable(false);
        jbtnSave.setMargin(new java.awt.Insets(2, 8, 2, 8));
        jbtnSave.setRequestFocusEnabled(false);
        jbtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSaveActionPerformed(evt);
            }
        });

        jbtnClose.setBackground(new java.awt.Color(255, 255, 255));
        jbtnClose
                .setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/editdelete.png"))); // NOI18N
        jbtnClose.setMnemonic('c');
        jbtnClose.setToolTipText("Close");
        jbtnClose.setFocusPainted(false);
        jbtnClose.setFocusable(false);
        jbtnClose.setMargin(new java.awt.Insets(2, 8, 2, 8));
        jbtnClose.setRequestFocusEnabled(false);
        jbtnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCloseActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel6Layout.createSequentialGroup().add(25, 25, 25)
                        .add(jbtnNew, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jbtnSave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jbtnClose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));
        jPanel6Layout
                .setVerticalGroup(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel6Layout.createSequentialGroup()
                                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING,
                                                jPanel6Layout.createSequentialGroup().add(17, 17, 17)
                                                        .add(jSeparator1,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(org.jdesktop.layout.GroupLayout.LEADING,
                                                jPanel6Layout.createSequentialGroup().add(5, 5, 5).add(jPanel6Layout
                                                        .createParallelGroup(
                                                                org.jdesktop.layout.GroupLayout.LEADING, false)
                                                        .add(jbtnClose,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0,
                                                                Short.MAX_VALUE)
                                                        .add(jbtnSave,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0,
                                                                Short.MAX_VALUE)
                                                        .add(jbtnNew,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30,
                                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        setEnabled(true);
        setEnabled(true);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(layout.createSequentialGroup().addContainerGap().add(jPanel1,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(layout.createSequentialGroup().add(331, 331, 331).add(jPanel6,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(234, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup().add(23, 23, 23)
                        .add(jPanel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(92, Short.MAX_VALUE)));

        getAccessibleContext().setAccessibleParent(this);
    }// </editor-fold>//GEN-END:initComponents

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

        // Add your handling code here:
        clearTxtFields();
        setCustomerId();
        jbtnSave.setEnabled(true);
    }//GEN-LAST:event_jbtnNewActionPerformed

    private void setCustomerId() {
        String customerId = null;
        try {
            try {
                customerId = dlSales.getCustomerId();
            } catch (BasicException ex) {
                Logger.getLogger(JCustomerPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (NullPointerException ex) {
            customerId = "";
        }
        String storeName = (JCustomerPanel.app).getProperties().getStoreName();
        String[] cusValue;
        if (customerId.equals(null) || customerId.equals("")) {
            customerId = storeName + "-" + 10001;
        } else {
            cusValue = customerId.split("-");
            int value = (Integer.parseInt(cusValue[1])) + 1;
            customerId = storeName + "-" + value;
        }
        m_jCustomerId.setText(customerId);
        m_jCustomerId.setEditable(false);
    }

    private void jbtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSaveActionPerformed
        CustomerInfoExt cinfo = new CustomerInfoExt("0000");
        String cId = null;
        cId = UUID.randomUUID().toString();
        setCustomerObjectVals(cinfo);
        try {
            if (checkFields()) {
                List<AccountPojo> list = dlCustomers.getAccountValue();
                System.out.println("INSIDE TRY");
                if (list != null && list.size() != 0) {
                    Receivable = list.get(0).getReceivable().toString();
                    Advance = list.get(0).getAdvance().toString();
                    cinfo.setReceivable(Receivable);
                    cinfo.setAdvance(Advance);
                }
                saveCustomerData(cinfo, cId);
                setCustomerId();
            }

        } catch (BasicException ex) {
            Logger.getLogger(JCustomerPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jbtnSaveActionPerformed

    private void jbtnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCloseActionPerformed
        dispose();// TODO add your handling code here:
    }//GEN-LAST:event_jbtnCloseActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbtnClose;
    private javax.swing.JButton jbtnNew;
    private javax.swing.JButton jbtnSave;
    private javax.swing.JTextField m_jCustomerId;
    private javax.swing.JTextField m_jName;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtAddress1;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtCountry;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtPostal;
    private javax.swing.JTextField txtRegion;
    // End of variables declaration//GEN-END:variables

    private static Window getWindow(Component parent) {
        if (parent == null) {
            return new JFrame();
        } else if (parent instanceof Frame || parent instanceof Dialog) {
            return (Window) parent;
        } else {
            return getWindow(parent.getParent());
        }
    }

    private void saveCustomerData(CustomerInfoExt cinfo, String id) throws BasicException {
        String cusId = id.replace("-", "");
        dlCustomers.insertCustomer(cinfo, cusId);
        populateList();
        clearTxtFields();
    }

    private boolean checkFields() {
        // Pattern pEmail = Pattern.compile("^(.+)@([^@]+[^.])$");
        Pattern pEmail = Pattern.compile("^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$");
        //  Pattern pEmail1 = Pattern.compile(".");
        Pattern pNum = Pattern.compile("[+-]?[\\d,]+\\.?\\d+");

        boolean retval = true;
        if ("".equals(m_jName.getText())) {
            JOptionPane.showMessageDialog(this, "Please enter the name");
            retval = false;
            m_jName.setFocusable(true);
        } else {
            if ("".equals(txtPhone.getText())) {
                JOptionPane.showMessageDialog(this, "Please enter the phoneNo");
                retval = false;
                txtPhone.setFocusable(true);
            } else if (!pNum.matcher(txtPhone.getText()).matches()) {
                JOptionPane.showMessageDialog(this, "Please enter the valid phoneNo");
                retval = false;
                txtPhone.setText("");
                txtPhone.setFocusable(true);
            }
            //        else{
            //            if ("".equals(txtEmail.getText())) {
            //                JOptionPane.showMessageDialog(this, "Please enter the e-mail");
            //                retval = false;
            //                 txtEmail.setFocusable(true);
            //        }else if(!pEmail.matcher(txtEmail.getText()).matches()){
            //                JOptionPane.showMessageDialog(this, "Please enter the valid e-mail");
            //                retval = false;
            //                txtEmail.setText("");
            //                 txtEmail.setFocusable(true);
            //        }
            else {
                if (txtPhone.getText() != null) {
                    int phoneCount = 0;
                    try {
                        phoneCount = dlCustomers.getPhoneCount(txtPhone.getText());
                    } catch (BasicException ex) {
                        Logger.getLogger(JCustomerPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    if (phoneCount == 1) {
                        JOptionPane.showMessageDialog(this, "Entered Phone No. is already exists");
                        txtPhone.setText(null);
                        txtPhone.setFocusable(true);
                        retval = false;

                    }
                    //                else{
                    //                if(txtEmail.getText()!=null){
                    //                int emailCount = 0;
                    //                try {
                    //                   emailCount = dlCustomers.getEmailCount(txtEmail.getText());
                    //                } catch (BasicException ex) {
                    //                    Logger.getLogger(JCustomerPanel.class.getName()).log(Level.SEVERE, null, ex);
                    //                }
                    //                if(emailCount==1){
                    //                    JOptionPane.showMessageDialog(this, "Entered email id is already exists");
                    //                    txtEmail.setText(null);
                    //                      txtEmail.setFocusable(true);
                    //                    retval = false;
                    //                }
                    //}}
                    //   }
                }
            }
        } //else if(){
        //
        //        }
        return retval;
    }

    private void populateList() throws BasicException {

        //        model = new DefaultListModel();
        //        m_jCustomersList.setModel(model);
        //        li = dlCustomers.getCustomerList2();
        //        for (int i = 0; i < li.size(); i++) {
        //            String cName = li.get(i).getName();
        //            model.add(i, cName);
        //        }
    }

    private void selectionChangeEvt(javax.swing.event.ListSelectionEvent evt) {

        //        if (evt.getValueIsAdjusting()) {
        //            int i = m_jCustomersList.getSelectedIndex();
        //            String id = li.get(i).getId();
        //            m_jName.setText(li.get(i).getName());
        //            m_jVisible.setSelected(li.get(i).isVisible());
        //            txtFirstName.setText(li.get(i).getFirstname());
        //            txtLastName.setText(li.get(i).getLastname());
        //            txtEmail.setText(li.get(i).getEmail());
        //            txtPhone.setText(li.get(i).getPhone());
        //            txtAddress.setText(li.get(i).getAddress());
        //            txtAddress2.setText(li.get(i).getAddress2());
        //            txtPostal.setText(li.get(i).getPostal());
        //            txtCity.setText(li.get(i).getCity());
        //            txtRegion.setText(li.get(i).getRegion());
        //            txtCountry.setText(li.get(i).getCountry());
        //            m_jNotes.setText(li.get(i).getNotes());
        //        }
    }

    private void clearTxtFields() {

        m_jName.setText(null);
        //m_jNotes.setText(null);
        // m_jVisible.setSelected(true);
        //  txtFirstName.setText(null);
        //   txtLastName.setText(null);
        txtEmail.setText(null);
        txtPhone.setText(null);
        txtAddress.setText(null);
        txtAddress1.setText(null);
        //   txtAddress2.setText(null);
        txtPostal.setText(null);
        txtCity.setText(null);
        txtRegion.setText(null);
        txtCountry.setText(null);
        //        m_jCustomersList.clearSelection();
    }

    private void updateCustomerData(String id) throws BasicException {
        CustomerInfoExt c = new CustomerInfoExt(id);
        setCustomerObjectVals(c);
        dlCustomers.updateAllCustomerInfo(c);
    }

    //    private ArrayList<String> callWS(CustomerInfoExt customer) throws ParserConfigurationException {

    //        ArrayList<String> retVal = new ArrayList<String>();
    //        try {
    //            customerWSXml xml = new customerWSXml(dlCustomers, customer);
    //            xml.generateXml();
    //            String result = xml.getCustomerWSXml();
    //            //System.out.println(result);
    //            HttpClient client = new HttpClient();
    //            AppConfig aconfig = new AppConfig(new File(System.getProperty("user.home") + "/openbravopos.properties"));
    //            aconfig.load();
    //
    //            PostMethod method = new PostMethod(aconfig.getProperty("erp.customeruri"));
    //            method.addParameter("l", aconfig.getProperty("erp.username"));
    //            method.addParameter("p", aconfig.getProperty("erp.password"));
    //
    //            method.addParameter("posCustomer", result);
    //            int statusCode = client.executeMethod(method);
    //            if (statusCode == HttpStatus.SC_OK) {
    //                String xmlString = new String(method.getResponseBody());
    //                System.out.println("xmlString " + xmlString);
    //                String res = xml.getStatusMsg(xmlString);
    //                retVal.add(0, res);
    //                String erpid = xml.getErpId(xmlString);
    //                retVal.add(1, erpid);
    //            }
    //        } catch (IOException ex) {
    //            //Logger.getLogger(JCustomerPanel.class.getName()).log(Level.SEVERE, null, ex);
    //            JOptionPane.showMessageDialog(this, "Internet is down. please try to insert after some time");
    //        }

    //        return retVal;
    //    }

}