diff --git a/pom.xml b/pom.xml
index 65299e6..c741f94 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,8 +7,8 @@
jar
UTF-8
- 1.7
- 1.7
+ 1.8
+ 1.8
diff --git a/src/main/java/com/openbravo/data/gui/Populator.java b/src/main/java/com/openbravo/data/gui/Populator.java
new file mode 100644
index 0000000..5f5dfe1
--- /dev/null
+++ b/src/main/java/com/openbravo/data/gui/Populator.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.data.gui;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+@FunctionalInterface
+public interface Populator {
+ public void populate(T data);
+}
diff --git a/src/main/java/com/openbravo/pos/customers/DataLogicCustomers.java b/src/main/java/com/openbravo/pos/customers/DataLogicCustomers.java
index 4285b48..26a5a4e 100755
--- a/src/main/java/com/openbravo/pos/customers/DataLogicCustomers.java
+++ b/src/main/java/com/openbravo/pos/customers/DataLogicCustomers.java
@@ -24,6 +24,7 @@
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.BeanFactoryDataSingle;
+import com.openbravo.pos.forms.DataLogicSales;
/**
* @author JG uniCenta
@@ -48,6 +49,36 @@ public class DataLogicCustomers extends BeanFactoryDataSingle {
Datas.BOOLEAN,
Datas.STRING};
+ private static final String[] fields = new String[]
+ {
+ "ID",
+ "TAXID",
+ "SEARCHKEY",
+ "NAME",
+ "NOTES",
+ "VISIBLE",
+ "CARD",
+ "MAXDEBT",
+ "CURDATE",
+ "CURDEBT",
+ "FIRSTNAME",
+ "LASTNAME",
+ "EMAIL",
+ "PHONE",
+ "PHONE2",
+ "FAX",
+ "ADDRESS",
+ "ADDRESS2",
+ "POSTAL",
+ "CITY",
+ "REGION",
+ "COUNTRY",
+ "TAXCATEGORY",
+ "IMAGE"
+ };
+
+ private static String baseSentence;
+
/**
*
* @param s
@@ -58,31 +89,7 @@ public void init(Session s){
this.s = s;
tcustomers = new TableDefinition(s
, "CUSTOMERS"
- , new String[] {
- "ID",
- "TAXID",
- "SEARCHKEY",
- "NAME",
- "NOTES",
- "VISIBLE",
- "CARD",
- "MAXDEBT",
- "CURDATE",
- "CURDEBT",
- "FIRSTNAME",
- "LASTNAME",
- "EMAIL",
- "PHONE",
- "PHONE2",
- "FAX",
- "ADDRESS",
- "ADDRESS2",
- "POSTAL",
- "CITY",
- "REGION",
- "COUNTRY",
- "TAXCATEGORY",
- "IMAGE" }
+ , fields
, new String[] {
"ID",
AppLocal.getIntString("label.taxid"),
@@ -160,6 +167,14 @@ public void init(Session s){
Formats.NULL }
, new int[] {0}
);
+
+ StringBuilder sqlBuilder = new StringBuilder("SELECT ");
+ for (int i = 0; i < fields.length; i++) {
+ sqlBuilder.append(fields[i]);
+ sqlBuilder.append(", ");
+ }
+ sqlBuilder.append(" FROM CUSTOMERS");
+ this.baseSentence = sqlBuilder.toString();
}
// JG 20 Sept 12 extended for Postal - CustomerList list
@@ -299,5 +314,18 @@ public int execInTransaction(Object params) throws BasicException {
*/
public final TableDefinition getTableCustomers() {
return tcustomers;
- }
+ }
+
+ public CustomerInfoExt findCustomersBy(String field, Object value) {
+
+ StringBuilder sqlBuilder = new StringBuilder(this.baseSentence);
+ sqlBuilder.append(" WHERE ");
+ sqlBuilder.append(field);
+ sqlBuilder.append(" = ?");
+
+ PreparedSentence sentence = new PreparedSentence(this.s, sqlBuilder.toString());
+
+ // will be implemented for next release
+ return null;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.form b/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.form
new file mode 100644
index 0000000..aaa01a5
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.form
@@ -0,0 +1,389 @@
+
+
+
diff --git a/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.java b/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.java
new file mode 100644
index 0000000..a051705
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/customers/JPanelCustomerFields.java
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.customers;
+
+import com.openbravo.data.gui.Populator;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.pos.forms.AppLocal;
+import com.openbravo.pos.panels.JPanelPopulatable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import javax.swing.JComboBox;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+public class JPanelCustomerFields extends JPanelPopulatable {
+
+ public static String CARD_GENERATE = "GENERATE";
+
+ private ArrayList combos = new ArrayList<>();
+
+ /**
+ * Creates new form JPanelCustomers
+ */
+ public JPanelCustomerFields() {
+ initComponents();
+
+ combos.add(cmbCard);
+ combos.add(cmbAccountId);
+ combos.add(cmbSearchKey);
+ combos.add(cmbFirstName);
+ combos.add(cmbTaxCat);
+ combos.add(cmbLastName);
+ combos.add(cmbCreditLimit);
+ combos.add(cmbEmail);
+ combos.add(cmbPhone1);
+ combos.add(cmbPhone2);
+ combos.add(cmbFax);
+ combos.add(cmbAddress1);
+ combos.add(cmbAddress2);
+ combos.add(cmbCity);
+ combos.add(cmbRegion);
+ combos.add(cmbZip);
+ combos.add(cmbCountry);
+ combos.add(cmbNotes);
+ combos.add(cmbVisible);
+ }
+
+ @Override
+ public HashMap getConfig() {
+ HashMap config = new HashMap<>();
+
+ config.put("card", chkCardGenerate.isSelected() ? CARD_GENERATE : (String) cmbCard.getSelectedItem());
+ config.put("taxid", (String) cmbTaxCat.getSelectedItem());
+ config.put("notes", (String) cmbNotes.getSelectedItem());
+ config.put("visible", (String) cmbVisible.getSelectedItem());
+ config.put("firstname", (String) cmbFirstName.getSelectedItem());
+ config.put("lastname", (String) cmbLastName.getSelectedItem());
+ config.put("email", (String) cmbEmail.getSelectedItem());
+ config.put("phone", (String) cmbPhone1.getSelectedItem());
+ config.put("phone2", (String) cmbPhone2.getSelectedItem());
+ config.put("fax", (String) cmbFax.getSelectedItem());
+ config.put("address", (String) cmbAddress1.getSelectedItem());
+ config.put("address2", (String) cmbAddress2.getSelectedItem());
+ config.put("postal", (String) cmbZip.getSelectedItem());
+ config.put("city", (String) cmbCity.getSelectedItem());
+ config.put("region", (String) cmbRegion.getSelectedItem());
+ config.put("country", (String) cmbCountry.getSelectedItem());
+ config.put("searchkey", (String) cmbSearchKey.getSelectedItem());
+ config.put("taxid", (String) cmbTaxCat.getSelectedItem());
+ config.put("maxdept", (String) cmbCreditLimit.getSelectedItem());
+
+ return config;
+ }
+
+ @Override
+ public Populator> getPopulator() {
+ return headerList -> {
+ for (JComboBox box : this.combos) {
+ box.addItem("");
+ for (String header : headerList) {
+ box.addItem(header);
+ }
+
+ if (headerList.contains(box.getName())) {
+ box.setSelectedItem(box.getName());
+ }
+ }
+ };
+ }
+
+ @Override
+ public boolean deactivate() {
+ this.combos.stream().forEach((box) -> {
+ box.removeAllItems();
+ });
+ return true;
+ }
+
+
+
+ /**
+ * 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")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ pnlFields = new javax.swing.JPanel();
+ lblCard = new javax.swing.JLabel();
+ cmbCard = new javax.swing.JComboBox<>();
+ chkCardGenerate = new javax.swing.JCheckBox();
+ lblDummy = new javax.swing.JLabel();
+ lblAccountId = new javax.swing.JLabel();
+ cmbAccountId = new javax.swing.JComboBox<>();
+ lblSearchKey = new javax.swing.JLabel();
+ cmbSearchKey = new javax.swing.JComboBox<>();
+ lblFirstName = new javax.swing.JLabel();
+ cmbFirstName = new javax.swing.JComboBox<>();
+ lblTaxCat = new javax.swing.JLabel();
+ cmbTaxCat = new javax.swing.JComboBox<>();
+ lblLastName = new javax.swing.JLabel();
+ cmbLastName = new javax.swing.JComboBox<>();
+ lblCreditLimit = new javax.swing.JLabel();
+ cmbCreditLimit = new javax.swing.JComboBox<>();
+ lblEmail = new javax.swing.JLabel();
+ cmbEmail = new javax.swing.JComboBox<>();
+ lblPhone1 = new javax.swing.JLabel();
+ cmbPhone1 = new javax.swing.JComboBox<>();
+ lblPhone2 = new javax.swing.JLabel();
+ cmbPhone2 = new javax.swing.JComboBox<>();
+ lblFax = new javax.swing.JLabel();
+ cmbFax = new javax.swing.JComboBox<>();
+ lblAddress1 = new javax.swing.JLabel();
+ cmbAddress1 = new javax.swing.JComboBox<>();
+ lblAddress2 = new javax.swing.JLabel();
+ cmbAddress2 = new javax.swing.JComboBox<>();
+ lblCity = new javax.swing.JLabel();
+ cmbCity = new javax.swing.JComboBox<>();
+ lblRegion = new javax.swing.JLabel();
+ cmbRegion = new javax.swing.JComboBox<>();
+ lblZip = new javax.swing.JLabel();
+ cmbZip = new javax.swing.JComboBox<>();
+ lblCountry = new javax.swing.JLabel();
+ cmbCountry = new javax.swing.JComboBox<>();
+ lblNotes = new javax.swing.JLabel();
+ cmbNotes = new javax.swing.JComboBox<>();
+ lblVisible = new javax.swing.JLabel();
+ cmbVisible = new javax.swing.JComboBox<>();
+
+ setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
+
+ pnlFields.setLayout(new java.awt.GridLayout(0, 4, 10, 0));
+
+ lblCard.setText(AppLocal.getIntString("label.card")); // NOI18N
+ pnlFields.add(lblCard);
+
+ cmbCard.setEnabled(false);
+ cmbCard.setName("card"); // NOI18N
+ pnlFields.add(cmbCard);
+
+ chkCardGenerate.setSelected(true);
+ chkCardGenerate.setText(AppLocal.getIntString("label.generate")); // NOI18N
+ chkCardGenerate.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ chkCardGenerateActionPerformed(evt);
+ }
+ });
+ pnlFields.add(chkCardGenerate);
+ pnlFields.add(lblDummy);
+
+ lblAccountId.setText(AppLocal.getIntString("label.taxid")); // NOI18N
+ pnlFields.add(lblAccountId);
+
+ cmbAccountId.setToolTipText("");
+ cmbAccountId.setName("id"); // NOI18N
+ pnlFields.add(cmbAccountId);
+
+ lblSearchKey.setText(AppLocal.getIntString("label.searchkey")); // NOI18N
+ pnlFields.add(lblSearchKey);
+
+ cmbSearchKey.setName("search_key"); // NOI18N
+ pnlFields.add(cmbSearchKey);
+
+ lblFirstName.setText(AppLocal.getIntString("label.firstname")); // NOI18N
+ pnlFields.add(lblFirstName);
+
+ cmbFirstName.setName("first_name"); // NOI18N
+ pnlFields.add(cmbFirstName);
+
+ lblTaxCat.setText(AppLocal.getIntString("label.custtaxcategory")); // NOI18N
+ pnlFields.add(lblTaxCat);
+
+ cmbTaxCat.setName("taxcat"); // NOI18N
+ pnlFields.add(cmbTaxCat);
+
+ lblLastName.setText(AppLocal.getIntString("label.lastname")); // NOI18N
+ pnlFields.add(lblLastName);
+
+ cmbLastName.setName("last_name"); // NOI18N
+ pnlFields.add(cmbLastName);
+
+ lblCreditLimit.setText(AppLocal.getIntString("label.maxdebt")); // NOI18N
+ pnlFields.add(lblCreditLimit);
+
+ cmbCreditLimit.setName("credit_limit"); // NOI18N
+ pnlFields.add(cmbCreditLimit);
+
+ lblEmail.setText(AppLocal.getIntString("label.email")); // NOI18N
+ pnlFields.add(lblEmail);
+
+ cmbEmail.setName("email"); // NOI18N
+ pnlFields.add(cmbEmail);
+
+ lblPhone1.setText(AppLocal.getIntString("label.phone")); // NOI18N
+ pnlFields.add(lblPhone1);
+
+ cmbPhone1.setName("telephone"); // NOI18N
+ pnlFields.add(cmbPhone1);
+
+ lblPhone2.setText(AppLocal.getIntString("label.phone2")); // NOI18N
+ pnlFields.add(lblPhone2);
+
+ cmbPhone2.setName("mobile"); // NOI18N
+ pnlFields.add(cmbPhone2);
+
+ lblFax.setText(AppLocal.getIntString("label.fax")); // NOI18N
+ pnlFields.add(lblFax);
+
+ cmbFax.setName("fax"); // NOI18N
+ pnlFields.add(cmbFax);
+
+ lblAddress1.setText(AppLocal.getIntString("label.address")); // NOI18N
+ pnlFields.add(lblAddress1);
+
+ cmbAddress1.setName("address"); // NOI18N
+ pnlFields.add(cmbAddress1);
+
+ lblAddress2.setText(AppLocal.getIntString("label.address2")); // NOI18N
+ pnlFields.add(lblAddress2);
+
+ cmbAddress2.setName("address2"); // NOI18N
+ pnlFields.add(cmbAddress2);
+
+ lblCity.setText(AppLocal.getIntString("label.city")); // NOI18N
+ pnlFields.add(lblCity);
+
+ cmbCity.setName("city"); // NOI18N
+ pnlFields.add(cmbCity);
+
+ lblRegion.setText(AppLocal.getIntString("label.region")); // NOI18N
+ pnlFields.add(lblRegion);
+
+ cmbRegion.setName("state"); // NOI18N
+ pnlFields.add(cmbRegion);
+
+ lblZip.setText(AppLocal.getIntString("label.postal")); // NOI18N
+ pnlFields.add(lblZip);
+
+ cmbZip.setName("zip"); // NOI18N
+ pnlFields.add(cmbZip);
+
+ lblCountry.setText(AppLocal.getIntString("label.country")); // NOI18N
+ pnlFields.add(lblCountry);
+
+ cmbCountry.setName("country"); // NOI18N
+ pnlFields.add(cmbCountry);
+
+ lblNotes.setText(AppLocal.getIntString("label.notes")); // NOI18N
+ pnlFields.add(lblNotes);
+
+ cmbNotes.setName("comments"); // NOI18N
+ pnlFields.add(cmbNotes);
+
+ lblVisible.setText(AppLocal.getIntString("label.visible")); // NOI18N
+ pnlFields.add(lblVisible);
+
+ cmbVisible.setName("visible"); // NOI18N
+ pnlFields.add(cmbVisible);
+
+ add(pnlFields);
+ }// //GEN-END:initComponents
+
+ private void chkCardGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkCardGenerateActionPerformed
+ cmbCard.setEnabled(!chkCardGenerate.isSelected());
+ }//GEN-LAST:event_chkCardGenerateActionPerformed
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JCheckBox chkCardGenerate;
+ private javax.swing.JComboBox cmbAccountId;
+ private javax.swing.JComboBox cmbAddress1;
+ private javax.swing.JComboBox cmbAddress2;
+ private javax.swing.JComboBox cmbCard;
+ private javax.swing.JComboBox cmbCity;
+ private javax.swing.JComboBox cmbCountry;
+ private javax.swing.JComboBox cmbCreditLimit;
+ private javax.swing.JComboBox cmbEmail;
+ private javax.swing.JComboBox cmbFax;
+ private javax.swing.JComboBox cmbFirstName;
+ private javax.swing.JComboBox cmbLastName;
+ private javax.swing.JComboBox cmbNotes;
+ private javax.swing.JComboBox cmbPhone1;
+ private javax.swing.JComboBox cmbPhone2;
+ private javax.swing.JComboBox cmbRegion;
+ private javax.swing.JComboBox cmbSearchKey;
+ private javax.swing.JComboBox cmbTaxCat;
+ private javax.swing.JComboBox cmbVisible;
+ private javax.swing.JComboBox cmbZip;
+ private javax.swing.JLabel lblAccountId;
+ private javax.swing.JLabel lblAddress1;
+ private javax.swing.JLabel lblAddress2;
+ private javax.swing.JLabel lblCard;
+ private javax.swing.JLabel lblCity;
+ private javax.swing.JLabel lblCountry;
+ private javax.swing.JLabel lblCreditLimit;
+ private javax.swing.JLabel lblDummy;
+ private javax.swing.JLabel lblEmail;
+ private javax.swing.JLabel lblFax;
+ private javax.swing.JLabel lblFirstName;
+ private javax.swing.JLabel lblLastName;
+ private javax.swing.JLabel lblNotes;
+ private javax.swing.JLabel lblPhone1;
+ private javax.swing.JLabel lblPhone2;
+ private javax.swing.JLabel lblRegion;
+ private javax.swing.JLabel lblSearchKey;
+ private javax.swing.JLabel lblTaxCat;
+ private javax.swing.JLabel lblVisible;
+ private javax.swing.JLabel lblZip;
+ private javax.swing.JPanel pnlFields;
+ // End of variables declaration//GEN-END:variables
+
+ @Override
+ public void setConfig(HashMap config) {
+ }
+
+ @Override
+ public void saveData(SaveProvider spr) {
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.form b/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.form
new file mode 100644
index 0000000..a5688c8
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.form
@@ -0,0 +1,47 @@
+
+
+
diff --git a/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.java b/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.java
new file mode 100644
index 0000000..e8dca2d
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/customers/JPanelCustomerList.java
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.customers;
+
+import com.openbravo.basic.BasicException;
+import com.openbravo.data.gui.Populator;
+import com.openbravo.data.loader.TableDefinition;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.format.Formats;
+import com.openbravo.pos.forms.AppLocal;
+import com.openbravo.pos.panels.JPanelPopulatable;
+import com.openbravo.pos.util.StringUtils;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.UUID;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.table.AbstractTableModel;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+public class JPanelCustomerList extends JPanelPopulatable {
+ private final CustomerListModel model = new CustomerListModel();
+ private HashMap config;
+
+ /**
+ * Creates new form JPanelItemList
+ */
+ public JPanelCustomerList() {
+ initComponents();
+ }
+
+ /**
+ * 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")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jScrollPane1 = new javax.swing.JScrollPane();
+ tblData = new javax.swing.JTable();
+
+ setLayout(new java.awt.BorderLayout());
+
+ tblData.setModel(model);
+ jScrollPane1.setViewportView(tblData);
+
+ add(jScrollPane1, java.awt.BorderLayout.CENTER);
+ }// //GEN-END:initComponents
+
+
+ @Override
+ public Populator>> getPopulator() {
+ return (ArrayList> data) -> {
+ if (this.config == null) {
+ throw new IllegalStateException("No config has been set. Don't know how to treat data.");
+ }
+
+ ArrayList customers = new ArrayList<>();
+
+ data.forEach((HashMap record) -> {
+ CustomerInfoExt cust = new CustomerInfoExt(null);
+
+ String card = this.config.get("card").equals("GENERATE") ? "c" + StringUtils.getCardNumber() : record.get(this.config.get("card"));
+
+ cust.setCard(card);
+ cust.setSearchkey(card);
+ cust.setFirstname(record.get(this.config.get("firstname")));
+ cust.setLastname(record.get(this.config.get("lastname")));
+ cust.setName(record.get(this.config.get("firstname")) + " " + record.get(this.config.get("lastname")));
+ cust.setTaxid(record.get(this.config.get("taxid")));
+ cust.setNotes(record.get(this.config.get("notes")));
+ cust.setVisible(true);
+ cust.setEmail(record.get(this.config.get("email")));
+ cust.setPhone(record.get(this.config.get("phone")));
+ cust.setPhone2(record.get(this.config.get("phone2")));
+ cust.setFax(record.get(this.config.get("fax")));
+ cust.setAddress(record.get(this.config.get("address")));
+ cust.setAddress2(record.get(this.config.get("address2")));
+ cust.setPostal(record.get(this.config.get("postal")));
+ cust.setCity(record.get(this.config.get("city")));
+ cust.setCountry(record.get(this.config.get("country")));
+ cust.setRegion(record.get(this.config.get("region")));
+
+ Double maxDept = 0d;
+ if (record.get(this.config.get("maxdept")) != null && record.get(this.config.get("maxdept")).length() > 0) {
+ try {
+ maxDept = Double.valueOf(record.get(this.config.get("maxdept")));
+ } catch (NumberFormatException ex) {
+ Logger.getLogger(JPanelCustomerList.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ cust.setMaxdebt(maxDept);
+
+ boolean isExisting = false;
+ boolean doImport = !isExisting;
+
+ customers.add(new CustomerListItem(cust, isExisting, doImport));
+ });
+
+ this.model.setData(customers);
+ };
+ }
+
+ @Override
+ public HashMap getConfig() {
+ return null;
+ }
+
+ @Override
+ public void setConfig(HashMap config) {
+ this.config = config;
+ }
+
+ @Override
+ public boolean deactivate() {
+ return this.model.clearData();
+ }
+
+ @Override
+ public void saveData(SaveProvider spr) {
+ this.model.getData().forEach((CustomerListItem item) -> {
+ Object[] customer = new Object[24];
+ try {
+ if (item.doImport) {
+ CustomerInfoExt custInfoExt = item.getCustomer();
+
+ customer[0] = custInfoExt.getId() == null ? UUID.randomUUID().toString() : custInfoExt.getId();
+ customer[1] = custInfoExt.getTaxid();
+ customer[2] = custInfoExt.getSearchkey();
+ customer[3] = custInfoExt.getName();
+ customer[4] = custInfoExt.getNotes();
+ customer[5] = custInfoExt.isVisible();
+ customer[6] = custInfoExt.getCard();
+ customer[7] = custInfoExt.getMaxdebt();
+ customer[8] = null;
+ customer[9] = null;
+
+ customer[10] = custInfoExt.getFirstname();
+ customer[11] = custInfoExt.getLastname();
+ customer[12] = custInfoExt.getEmail();
+ customer[13] = custInfoExt.getPhone();
+ customer[14] = custInfoExt.getPhone2();
+ customer[15] = custInfoExt.getFax();
+
+ customer[16] = custInfoExt.getAddress();
+ customer[17] = custInfoExt.getAddress2();
+ customer[18] = custInfoExt.getPostal();
+ customer[19] = custInfoExt.getCity();
+ customer[20] = custInfoExt.getRegion();
+ customer[21] = custInfoExt.getCountry();
+
+ customer[22] = null;
+ customer[23] = null;
+
+ if (item.isExisting()) {
+ spr.updateData(customer);
+ } else {
+ spr.insertData(customer);
+ }
+ }
+ } catch (BasicException ex) {
+ Logger.getLogger(JPanelCustomerList.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTable tblData;
+ // End of variables declaration//GEN-END:variables
+
+ private class CustomerListModel extends AbstractTableModel {
+ private ArrayList customerList = new ArrayList<>();
+ private final HashMap colNames = new HashMap<>();
+ private final HashMap colTypes = new HashMap<>();
+
+ public CustomerListModel() {
+ colNames.put(0, AppLocal.getIntString("label.import"));
+ colNames.put(1, AppLocal.getIntString("label.entry_exists"));
+ colNames.put(2, AppLocal.getIntString("label.card"));
+ colNames.put(3, AppLocal.getIntString("label.firstname"));
+ colNames.put(4, AppLocal.getIntString("label.lastname"));
+ colNames.put(5, AppLocal.getIntString("label.address"));
+ colNames.put(6, AppLocal.getIntString("label.city"));
+ colNames.put(7, AppLocal.getIntString("label.email"));
+
+ colTypes.put(0, Boolean.class);
+ colTypes.put(1, Boolean.class);
+ colTypes.put(2, String.class);
+ colTypes.put(3, String.class);
+ colTypes.put(4, String.class);
+ colTypes.put(5, String.class);
+ colTypes.put(6, String.class);
+ colTypes.put(7, String.class);
+ }
+
+ public void setData(ArrayList customers) {
+ this.customerList = customers;
+
+ fireTableDataChanged();
+ }
+
+ public ArrayList getData() {
+ return this.customerList;
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ return this.colNames.get(column);
+ }
+
+ @Override
+ public Class> getColumnClass(int col) {
+ return this.colTypes.get(col);
+ }
+
+ @Override
+ public int getRowCount() {
+ return customerList.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return colNames.size();
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ CustomerListItem customer = this.customerList.get(rowIndex);
+
+ switch (columnIndex) {
+ case 0:
+ return customer.getDoImport();
+ case 1:
+ return customer.isExisting();
+ case 2:
+ return customer.getCustomer().getCard();
+ case 3:
+ return customer.getCustomer().getFirstname();
+ case 4:
+ return customer.getCustomer().getLastname();
+ case 5:
+ return customer.getCustomer().getAddress();
+ case 6:
+ return customer.getCustomer().getCity();
+ case 7:
+ return customer.getCustomer().getEmail();
+ }
+
+ return null;
+ }
+
+ public boolean clearData() {
+ this.customerList.clear();
+ fireTableDataChanged();
+ return this.getRowCount() == 0;
+ }
+
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ if (columnIndex == 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ this.customerList.get(rowIndex).setDoImport((Boolean) aValue);
+ }
+ }
+
+ private class CustomerListItem {
+ private CustomerInfoExt customer;
+ private boolean isExisting = false;
+ private boolean doImport = true;
+
+ public CustomerListItem(CustomerInfoExt customerInfoExt, boolean isExisting, boolean doImport) {
+ this.customer = customerInfoExt;
+ this.isExisting = isExisting;
+ this.doImport = doImport;
+ }
+
+ public CustomerInfoExt getCustomer() {
+ return customer;
+ }
+
+ public boolean isExisting() {
+ return isExisting;
+ }
+
+ public void setDoImport(boolean doIt) {
+ this.doImport = doIt;
+ }
+
+ public boolean getDoImport() {
+ return this.doImport;
+ }
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/forms/JPrincipalApp.java b/src/main/java/com/openbravo/pos/forms/JPrincipalApp.java
index a91f1e6..3ddad60 100755
--- a/src/main/java/com/openbravo/pos/forms/JPrincipalApp.java
+++ b/src/main/java/com/openbravo/pos/forms/JPrincipalApp.java
@@ -500,8 +500,6 @@ public void showTask(String sTaskClass) {
m_jLastView = m_jMyView;
setMenuVisible(getBounds().width > 800);
-// JG Added 10 Nov 12
- setMenuVisible(false);
showView(sTaskClass);
String sTitle = m_jMyView.getTitle();
diff --git a/src/main/java/com/openbravo/pos/imports/CustomersImportPanel.java b/src/main/java/com/openbravo/pos/imports/CustomersImportPanel.java
new file mode 100644
index 0000000..7d81edd
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/imports/CustomersImportPanel.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.imports;
+
+import com.openbravo.data.user.EditorRecord;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.pos.customers.DataLogicCustomers;
+import com.openbravo.pos.customers.JPanelCustomerFields;
+import com.openbravo.pos.customers.JPanelCustomerList;
+import com.unicenta.pozapps.forms.AppLocal;
+
+public class CustomersImportPanel extends JPanelCsvImporter {
+ @Override
+ protected void init() {
+ DataLogicCustomers dlCustomers = (DataLogicCustomers) app.getBean("com.openbravo.pos.customers.DataLogicCustomers");
+ this.tableDef = dlCustomers.getTableCustomers();
+
+ this.spr = new SaveProvider(this.tableDef, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23});
+
+ this.fieldConfigurator = new JPanelCustomerFields();
+ this.fieldConfigurator.setComponentOrientation(getComponentOrientation());
+ this.itemList = new JPanelCustomerList();
+ this.itemList.setComponentOrientation(getComponentOrientation());
+ this.container.add(this.fieldConfigurator, java.awt.BorderLayout.CENTER);
+ this.container.add(this.itemList, java.awt.BorderLayout.SOUTH);
+ }
+
+ @Override
+ public EditorRecord getEditor() {
+ return null;
+ }
+
+ @Override
+ public String getTitle() {
+ return AppLocal.getIntString("Menu.CSVCustomerImport");
+ }
+
+ @Override
+ public void saveData() {
+ this.itemList.saveData(this.spr);
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/imports/ImportException.java b/src/main/java/com/openbravo/pos/imports/ImportException.java
new file mode 100644
index 0000000..6ee0bb9
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/imports/ImportException.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.imports;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+public class ImportException extends RuntimeException {
+ public ImportException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/imports/JPanelCSV.form b/src/main/java/com/openbravo/pos/imports/JPanelCSV.form
deleted file mode 100755
index 86321ea..0000000
--- a/src/main/java/com/openbravo/pos/imports/JPanelCSV.form
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
diff --git a/src/main/java/com/openbravo/pos/imports/JPanelCSV.java b/src/main/java/com/openbravo/pos/imports/JPanelCSV.java
deleted file mode 100755
index e46ca6b..0000000
--- a/src/main/java/com/openbravo/pos/imports/JPanelCSV.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.openbravo.pos.imports;
-
-/**
- *
- * @author JG uniCenta
- */
-public class JPanelCSV extends javax.swing.JPanel {
-
- /**
- *
- */
- public JPanelCSV() {
- initComponents();
- }
-
- /**
- * 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")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
- );
- }// //GEN-END:initComponents
- // Variables declaration - do not modify//GEN-BEGIN:variables
- // End of variables declaration//GEN-END:variables
-}
diff --git a/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.form b/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.form
index a2478ef..0cf31cd 100755
--- a/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.form
+++ b/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.form
@@ -84,7 +84,7 @@
-
+
@@ -290,7 +290,6 @@
-
diff --git a/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.java b/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.java
index d89950a..35e67c1 100755
--- a/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.java
+++ b/src/main/java/com/openbravo/pos/imports/JPanelCSVImport.java
@@ -799,7 +799,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboReference.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jComboReference.setEnabled(false);
jComboReference.setMinimumSize(new java.awt.Dimension(32, 25));
- jComboReference.setOpaque(false);
jComboReference.setPreferredSize(new java.awt.Dimension(275, 30));
jComboReference.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -1304,7 +1303,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jImport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addContainerGap(41, Short.MAX_VALUE))
);
}// //GEN-END:initComponents
diff --git a/src/main/java/com/openbravo/pos/imports/JPanelCsvImporter.java b/src/main/java/com/openbravo/pos/imports/JPanelCsvImporter.java
new file mode 100644
index 0000000..6771706
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/imports/JPanelCsvImporter.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.imports;
+
+import com.csvreader.CsvReader;
+import com.openbravo.data.loader.TableDefinition;
+import com.openbravo.pos.panels.JPanelCSVFileChooser;
+import com.openbravo.pos.panels.JPanelPopulatable;
+import com.openbravo.pos.panels.JPanelTable2;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+public abstract class JPanelCsvImporter extends JPanelTable2 {
+ protected TableDefinition tableDef;
+ protected JPanelCSVFileChooser fileChooserPanel;
+ protected JPanelPopulatable fieldConfigurator;
+ protected JPanelPopulatable itemList;
+
+ private CsvReader csvReader;
+ private String csvFileName;
+ private char csvDelimiter;
+ private char csvQuote;
+ private String[] csvHeaders;
+
+ public abstract void saveData();
+
+ @Override
+ protected void init() {
+ }
+
+ @Override
+ public void activate() {
+ startNavigation();
+ }
+
+ @Override
+ protected void startNavigation() {
+ this.fileChooserPanel = new JPanelCSVFileChooser(this);
+ this.fileChooserPanel.setComponentOrientation(getComponentOrientation());
+ this.toolbar.add(this.fileChooserPanel);
+ }
+
+ @Override
+ public boolean deactivate() {
+ this.fieldConfigurator.deactivate();
+ this.fileChooserPanel.deactivate();
+ this.itemList.deactivate();
+ return true;
+ }
+
+ public void readCsvMetaData(String csvFileName, char delimiter, char quote) throws FileNotFoundException {
+ this.csvFileName = csvFileName;
+ this.csvDelimiter = delimiter;
+ this.csvQuote = quote;
+
+ initCsvReader();
+
+ try {
+ this.csvReader.readHeaders();
+ String[] headers = this.csvReader.getHeaders();
+
+ int recordCount = 0;
+ while (this.csvReader.skipRecord()) {
+ recordCount++;
+ }
+ ArrayList headerList = new ArrayList<>();
+ headerList.addAll(Arrays.asList(headers));
+
+ this.fileChooserPanel.getPopulator().populate(recordCount);
+ this.fieldConfigurator.getPopulator().populate(headerList);
+
+ this.csvReader.close();
+ } catch (IOException ex) {
+ Logger.getLogger(JPanelCsvImporter.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public void readCsvData() throws FileNotFoundException {
+ initCsvReader();
+
+ ArrayList> data = new ArrayList<>();
+
+ try {
+ this.csvReader.readHeaders();
+ while (this.csvReader.readRecord()) {
+ data.add(this.readCsvLine());
+ }
+ } catch (IOException ex) {
+ Logger.getLogger(JPanelCsvImporter.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ this.itemList.setConfig(this.fieldConfigurator.getConfig());
+ this.itemList.getPopulator().populate(data);
+ }
+
+ private void initCsvReader() throws FileNotFoundException {
+ if (this.csvFileName == null) {
+ throw new ImportException("No csv metadata present");
+ }
+
+ this.csvReader = new CsvReader(this.csvFileName, this.csvDelimiter, Charset.forName("UTF-8"));
+ this.csvReader.setTextQualifier(this.csvQuote);
+ }
+
+ private HashMap readCsvLine() throws IOException {
+ HashMap data = new HashMap<>();
+
+ if (this.csvHeaders == null) {
+ this.csvHeaders = this.csvReader.getHeaders();
+ }
+ String[] values = this.csvReader.getValues();
+
+ for (int i = 0; i < csvHeaders.length; i++) {
+ data.put(csvHeaders[i], values[i]);
+ }
+
+ return data;
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/imports/ProductsImportPanel.java b/src/main/java/com/openbravo/pos/imports/ProductsImportPanel.java
new file mode 100644
index 0000000..12877fa
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/imports/ProductsImportPanel.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.imports;
+
+import com.openbravo.data.user.EditorRecord;
+import com.openbravo.data.user.ListProvider;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.pos.panels.JPanelTable;
+
+public class ProductsImportPanel extends JPanelTable {
+
+ @Override
+ protected void init() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public EditorRecord getEditor() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public ListProvider getListProvider() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public SaveProvider getSaveProvider() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public String getTitle() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+}
diff --git a/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.form b/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.form
new file mode 100755
index 0000000..413e8cf
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.form
@@ -0,0 +1,203 @@
+
+
+
diff --git a/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.java b/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.java
new file mode 100755
index 0000000..6f8b2c2
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/panels/JPanelCSVFileChooser.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.panels;
+
+import com.openbravo.data.gui.Populator;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.pos.forms.AppLocal;
+import com.openbravo.pos.imports.JPanelCsvImporter;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.filechooser.FileNameExtensionFilter;
+
+public class JPanelCSVFileChooser extends JPanelPopulatable {
+
+ private static final String FILE_FILTER_DESCRIPTION = "CSV Files *.csv";
+ private static final String FILE_FILTER = "csv";
+ private static final char CSV_DEFAULT_DELIMITER = ',';
+ private static final char CSV_DEFAULT_QUOTE = '"';
+
+ private final JPanelCsvImporter csvImporter;
+ private final JFileChooser fileChooser;
+
+ /**
+ *
+ */
+ public JPanelCSVFileChooser(JPanelCsvImporter importer) {
+ this.csvImporter = importer;
+
+ initComponents();
+
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(FILE_FILTER_DESCRIPTION, FILE_FILTER);
+
+ this.fileChooser = new JFileChooser();
+ this.fileChooser.setFileFilter(filter);
+ this.fileChooser.setMultiSelectionEnabled(false);
+ }
+
+ /**
+ * 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")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jPanel3 = new javax.swing.JPanel();
+ jPanel1 = new javax.swing.JPanel();
+ lblFile = new javax.swing.JLabel();
+ txtFile = new javax.swing.JTextField();
+ btnFile = new javax.swing.JButton();
+ btnRead = new javax.swing.JButton();
+ btnSave = new javax.swing.JButton();
+ jPanel2 = new javax.swing.JPanel();
+ lblConfig = new javax.swing.JLabel();
+ lblDelim = new javax.swing.JLabel();
+ txtDelim = new javax.swing.JTextField();
+ lblQuote = new javax.swing.JLabel();
+ txtQuote = new javax.swing.JTextField();
+ lblRecordsFound = new javax.swing.JLabel();
+ txtRecordsFound = new javax.swing.JTextField();
+
+ setMaximumSize(new java.awt.Dimension(186, 84));
+ setLayout(new java.awt.BorderLayout());
+
+ jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.PAGE_AXIS));
+
+ jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
+
+ lblFile.setText(AppLocal.getIntString("label.csvfile")); // NOI18N
+ lblFile.setPreferredSize(new java.awt.Dimension(80, 16));
+ lblFile.setRequestFocusEnabled(false);
+ jPanel1.add(lblFile);
+
+ txtFile.setPreferredSize(new java.awt.Dimension(400, 30));
+ txtFile.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ txtFileActionPerformed(evt);
+ }
+ });
+ jPanel1.add(txtFile);
+
+ btnFile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/fileopen.png"))); // NOI18N
+ btnFile.setToolTipText(AppLocal.getIntString("label.csvfile")); // NOI18N
+ btnFile.setMargin(new java.awt.Insets(8, 2, 8, 2));
+ btnFile.setPreferredSize(new java.awt.Dimension(52, 40));
+ btnFile.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnFileActionPerformed(evt);
+ }
+ });
+ jPanel1.add(btnFile);
+
+ btnRead.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/ok.png"))); // NOI18N
+ btnRead.setToolTipText(AppLocal.getIntString("label.csv")); // NOI18N
+ btnRead.setEnabled(false);
+ btnRead.setMargin(new java.awt.Insets(8, 2, 8, 2));
+ btnRead.setPreferredSize(new java.awt.Dimension(52, 40));
+ btnRead.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnReadActionPerformed(evt);
+ }
+ });
+ jPanel1.add(btnRead);
+
+ btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/filesave.png"))); // NOI18N
+ btnSave.setToolTipText(AppLocal.getIntString("Button.Save")); // NOI18N
+ btnSave.setEnabled(false);
+ btnSave.setMargin(new java.awt.Insets(8, 2, 8, 2));
+ btnSave.setPreferredSize(new java.awt.Dimension(52, 40));
+ btnSave.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnSaveActionPerformed(evt);
+ }
+ });
+ jPanel1.add(btnSave);
+
+ jPanel3.add(jPanel1);
+
+ jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
+
+ lblConfig.setText(AppLocal.getIntString("label.options")); // NOI18N
+ lblConfig.setPreferredSize(new java.awt.Dimension(80, 16));
+ jPanel2.add(lblConfig);
+
+ lblDelim.setText(AppLocal.getIntString("label.csvdelimit")); // NOI18N
+ jPanel2.add(lblDelim);
+
+ txtDelim.setText(String.valueOf(CSV_DEFAULT_DELIMITER));
+ txtDelim.setPreferredSize(new java.awt.Dimension(32, 28));
+ txtDelim.addKeyListener(new java.awt.event.KeyAdapter() {
+ public void keyTyped(java.awt.event.KeyEvent evt) {
+ txtDelimKeyTypedHandler(evt);
+ }
+ });
+ jPanel2.add(txtDelim);
+
+ lblQuote.setText(AppLocal.getIntString("label.csvquote")); // NOI18N
+ jPanel2.add(lblQuote);
+
+ txtQuote.setText(String.valueOf(CSV_DEFAULT_QUOTE));
+ txtQuote.setPreferredSize(new java.awt.Dimension(32, 28));
+ txtQuote.addKeyListener(new java.awt.event.KeyAdapter() {
+ public void keyTyped(java.awt.event.KeyEvent evt) {
+ txtQuoteKeyTypedHandler(evt);
+ }
+ });
+ jPanel2.add(txtQuote);
+
+ lblRecordsFound.setText(AppLocal.getIntString("label.csvrecordsfound")); // NOI18N
+ jPanel2.add(lblRecordsFound);
+
+ txtRecordsFound.setEditable(false);
+ txtRecordsFound.setBackground(new java.awt.Color(204, 204, 204));
+ txtRecordsFound.setToolTipText("");
+ txtRecordsFound.setPreferredSize(new java.awt.Dimension(60, 28));
+ jPanel2.add(txtRecordsFound);
+
+ jPanel3.add(jPanel2);
+
+ add(jPanel3, java.awt.BorderLayout.CENTER);
+ }// //GEN-END:initComponents
+
+ private void btnReadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReadActionPerformed
+ try {
+ this.csvImporter.readCsvData();
+ this.btnSave.setEnabled(true);
+ } catch (FileNotFoundException ex) {
+ Logger.getLogger(JPanelCSVFileChooser.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }//GEN-LAST:event_btnReadActionPerformed
+
+ private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
+ if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
+ this.txtFile.setText(fileChooser.getSelectedFile().getAbsolutePath());
+ }
+
+ this.readCsvMetaData();
+ }//GEN-LAST:event_btnFileActionPerformed
+
+ private void txtDelimKeyTypedHandler(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDelimKeyTypedHandler
+ if (txtDelim.getText().length() > 0) {
+ evt.consume();
+ }
+ }//GEN-LAST:event_txtDelimKeyTypedHandler
+
+ private void txtQuoteKeyTypedHandler(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtQuoteKeyTypedHandler
+ if (txtQuote.getText().length() > 0) {
+ evt.consume();
+ }
+ }//GEN-LAST:event_txtQuoteKeyTypedHandler
+
+ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
+ this.csvImporter.saveData();
+ }//GEN-LAST:event_btnSaveActionPerformed
+
+ private void txtFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFileActionPerformed
+ this.readCsvMetaData();
+ }//GEN-LAST:event_txtFileActionPerformed
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton btnFile;
+ private javax.swing.JButton btnRead;
+ private javax.swing.JButton btnSave;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JPanel jPanel3;
+ private javax.swing.JLabel lblConfig;
+ private javax.swing.JLabel lblDelim;
+ private javax.swing.JLabel lblFile;
+ private javax.swing.JLabel lblQuote;
+ private javax.swing.JLabel lblRecordsFound;
+ private javax.swing.JTextField txtDelim;
+ private javax.swing.JTextField txtFile;
+ private javax.swing.JTextField txtQuote;
+ private javax.swing.JTextField txtRecordsFound;
+ // End of variables declaration//GEN-END:variables
+
+ @Override
+ public Populator getPopulator() {
+ return recordCount -> this.txtRecordsFound.setText(String.valueOf(recordCount));
+ }
+
+ @Override
+ public boolean deactivate() {
+ this.txtFile.setText("");
+ this.txtRecordsFound.setText("");
+ return true;
+ }
+
+ private void readCsvMetaData() {
+ if (this.txtFile.getText().length() > 0) {
+ try {
+ if (this.txtDelim.getText().length() < 1) {
+ this.txtDelim.setText(String.valueOf(CSV_DEFAULT_DELIMITER));
+ }
+ if (this.txtQuote.getText().length() < 1) {
+ this.txtQuote.setText(String.valueOf(CSV_DEFAULT_QUOTE));
+ }
+
+ this.csvImporter.readCsvMetaData(this.txtFile.getText(), this.txtDelim.getText().charAt(0), this.txtQuote.getText().charAt(0));
+ } catch (FileNotFoundException ex) {
+ Logger.getLogger(JPanelCSVFileChooser.class.getName()).log(
+ Level.WARNING, "{0}: {1}", new Object[]{ex.getMessage(), this.txtFile.getText()}
+ );
+ JOptionPane.showMessageDialog(this, ex.getMessage(),
+ AppLocal.getIntString("label.error.filenotfound.title"), JOptionPane.ERROR_MESSAGE);
+ }
+
+ this.btnRead.setEnabled(true);
+ this.btnSave.setEnabled(false);
+ }
+ }
+
+ @Override
+ public HashMap getConfig() {
+ return null;
+ }
+
+ @Override
+ public void setConfig(HashMap config) {
+ }
+
+ @Override
+ public void saveData(SaveProvider spr) {
+ }
+}
diff --git a/src/main/java/com/openbravo/pos/panels/JPanelPopulatable.java b/src/main/java/com/openbravo/pos/panels/JPanelPopulatable.java
new file mode 100644
index 0000000..54e9ea2
--- /dev/null
+++ b/src/main/java/com/openbravo/pos/panels/JPanelPopulatable.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Beat Luginbühl
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see .
+ */
+package com.openbravo.pos.panels;
+
+import com.openbravo.basic.BasicException;
+import com.openbravo.data.gui.Populator;
+import com.openbravo.data.user.SaveProvider;
+import com.openbravo.pos.forms.JPanelView;
+import java.util.HashMap;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+
+/**
+ *
+ * @author Beat Luginbühl
+ */
+public abstract class JPanelPopulatable extends JPanel implements JPanelView {
+ public abstract Populator getPopulator();
+
+ public abstract HashMap getConfig();
+
+ public abstract void setConfig(HashMap config);
+
+ public abstract void saveData(SaveProvider spr);
+
+ @Override
+ public String getTitle() {
+ return "";
+ }
+
+ @Override
+ public void activate() throws BasicException {
+ }
+
+ @Override
+ public JComponent getComponent() {
+ return this;
+ }
+
+}
diff --git a/src/main/java/com/openbravo/pos/panels/JPanelTable.form b/src/main/java/com/openbravo/pos/panels/JPanelTable.form
index f2727ff..acb29b9 100755
--- a/src/main/java/com/openbravo/pos/panels/JPanelTable.form
+++ b/src/main/java/com/openbravo/pos/panels/JPanelTable.form
@@ -28,6 +28,9 @@
+
+
+
@@ -37,6 +40,9 @@
+
+
+
diff --git a/src/main/java/com/openbravo/pos/panels/JPanelTable.java b/src/main/java/com/openbravo/pos/panels/JPanelTable.java
index 03cceda..377a9fe 100755
--- a/src/main/java/com/openbravo/pos/panels/JPanelTable.java
+++ b/src/main/java/com/openbravo/pos/panels/JPanelTable.java
@@ -268,8 +268,8 @@ private void initComponents() {
// Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JPanel container;
- private javax.swing.JPanel toolbar;
+ protected javax.swing.JPanel container;
+ protected javax.swing.JPanel toolbar;
// End of variables declaration//GEN-END:variables
}
diff --git a/src/main/resources/com/openbravo/pos/templates/Menu.Root.txt b/src/main/resources/com/openbravo/pos/templates/Menu.Root.txt
index 99fd161..e36eb1f 100755
--- a/src/main/resources/com/openbravo/pos/templates/Menu.Root.txt
+++ b/src/main/resources/com/openbravo/pos/templates/Menu.Root.txt
@@ -131,6 +131,8 @@ group = menu.addGroup("Menu.Backoffice");
submenu = group.addSubmenu("/com/openbravo/images/utilities.png", "Menu.Tools", "com.openbravo.pos.imports.JPanelCSV");
submenu.addTitle("Menu.Import");
submenu.addPanel("/com/openbravo/images/import.png", "Menu.CSVImport", "com.openbravo.pos.imports.JPanelCSVImport");
+ submenu.addPanel("/com/openbravo/images/import.png", "Menu.CSVProductsImport", "com.openbravo.pos.imports.ProductsImportPanel");
+ submenu.addPanel("/com/openbravo/images/import.png", "Menu.CSVCustomerImport", "com.openbravo.pos.imports.CustomersImportPanel");
submenu.addPanel("/com/openbravo/images/database.png", "Menu.CSVReset", "com.openbravo.pos.imports.JPanelCSVCleardb");
submenu.addTitle("Menu.Import.Reports");
submenu.addPanel("/com/openbravo/images/reports.png", "Menu.UpdatedPrices", "/com/openbravo/reports/updatedprices.bs");
diff --git a/src/main/resources/com/openbravo/pos/templates/Role.Administrator.xml b/src/main/resources/com/openbravo/pos/templates/Role.Administrator.xml
index 15a6202..17e6693 100755
--- a/src/main/resources/com/openbravo/pos/templates/Role.Administrator.xml
+++ b/src/main/resources/com/openbravo/pos/templates/Role.Administrator.xml
@@ -144,6 +144,8 @@
+
+
diff --git a/src/main/resources/com/openbravo/pos/templates/Role.Manager.xml b/src/main/resources/com/openbravo/pos/templates/Role.Manager.xml
index 279a64e..93d705b 100755
--- a/src/main/resources/com/openbravo/pos/templates/Role.Manager.xml
+++ b/src/main/resources/com/openbravo/pos/templates/Role.Manager.xml
@@ -145,6 +145,8 @@
+
+
diff --git a/src/main/resources/pos_messages.properties b/src/main/resources/pos_messages.properties
index 38fb584..ed44d36 100755
--- a/src/main/resources/pos_messages.properties
+++ b/src/main/resources/pos_messages.properties
@@ -57,7 +57,9 @@ Menu.Auxiliar=Auxiliary products
Menu.Backoffice=Administration
Menu.BarcodeSheet=Labels: Barcode
Menu.Breaks=Breaks
+Menu.CSVCustomerImport=Import Customers
Menu.CSVImport=Import CSV File
+Menu.CSVProductsImport=Import Products
Menu.CSVReset=Clear Import Database Log
Menu.CashFlow=Cash-Flow
Menu.CashRegisterLog=Transaction Log
@@ -95,6 +97,8 @@ Menu.ExtendedCashRegisterLog=Transaction Log: Extended
Menu.ExtendedSales=Extended Sales
Menu.Floors=Floors
Menu.Import=CSV Import
+Menu.Import.Customers=Import Customers
+Menu.Import.Products=Import Products
Menu.Import.Reports=CSV Import Reports
Menu.InvalidData=Invalid or duplicate data found
Menu.Inventory=Inventory
@@ -291,8 +295,9 @@ label.csvfile=File
label.csvimpostbtn=Import CSV
label.csvmissing=Missing Data
label.csvnewproducts=New Products
+label.csvquote=Quote
label.csvpriceupdated=Prices Updated
-label.csvread=Read Header
+label.csv=Read Records
label.csvrecordsfound=Records Found
label.csvresetimport=Reset Import Data
label.csvsellingintax=Sell Price includes Tax?
@@ -320,12 +325,15 @@ label.dutyname=Tax Name
label.dutyrate=Rate
label.editline=Edit Line
label.email=email
+label.entry_exists=Entry exists
label.epm.employee=Employee
label.epm.employee.id=Employee ID
label.epm.enddate=End Date
label.epm.notes=Notes
label.epm.startdate=Start Date
label.epm.visible=Visible
+label.error.filenotfound.title=File not found
+label.error.filenotfound.message=The specified path and file cannot be found.
label.fax=Fax
label.firstname=First Name
label.floorid=ID
@@ -338,8 +346,10 @@ label.fontsizelarge=Large Text
label.fontsizesmall=Font Size: small
label.fontweight=Bold Text
label.general=General
+label.generate=Generate
label.grossprofit=Gross Profit
label.image=Image
+label.import=Import
label.inputamount=Input box above keypad
label.integer=Integer
label.item=Item
@@ -371,11 +381,13 @@ label.money=Total
label.mooringcreatebtn=Create Ticket
label.mooringscreatefor=Create ticket for
label.name=Name
+label.new=New
label.nocashsales=No Sale - Drawer Openings
label.notes=Notes
label.noticketstoclose=No Bills to Close
label.nullcategory=(No Category)
label.order=Order
+label.options=Options
label.passwordnew=New Password
label.passwordold=Old Password
label.passwordrepeat=Repeat Password
@@ -686,3 +698,4 @@ label.barcodetype=Barcode
label.prodbarcodetype=Barcode Type
=
label.copyref=Use as barcode
+label.Options=jLabel1