summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2016-11-24 14:53:34 -0600
committerDavid McMackins II <contact@mcmackins.org>2016-11-24 14:53:34 -0600
commit682547a6507d8004325f828411439b322b646034 (patch)
tree1f61bc5c6dcf1cf8c785286585f46488d2101e49
parentb7591486530967a54b0c71a1577591767bfbe23e (diff)
Add quantity update interface
-rw-r--r--src/com/delwink/icebox/QuantityUpdate.java4
-rw-r--r--src/com/delwink/icebox/lang/en_US.lang5
-rw-r--r--src/com/delwink/icebox/swing/MainWindow.java12
-rw-r--r--src/com/delwink/icebox/swing/QuantityUpdateDialog.java138
-rw-r--r--src/com/delwink/icebox/table/QuantityUpdateTableModel.java99
5 files changed, 257 insertions, 1 deletions
diff --git a/src/com/delwink/icebox/QuantityUpdate.java b/src/com/delwink/icebox/QuantityUpdate.java
index 34995ed..840cee2 100644
--- a/src/com/delwink/icebox/QuantityUpdate.java
+++ b/src/com/delwink/icebox/QuantityUpdate.java
@@ -61,6 +61,10 @@ public class QuantityUpdate implements Iterable<Record> {
public void setDate(Date updateDate) {
this.updateDate = updateDate;
}
+
+ public List<Record> getRecords() {
+ return RECORDS;
+ }
@Override
public Iterator<Record> iterator() {
diff --git a/src/com/delwink/icebox/lang/en_US.lang b/src/com/delwink/icebox/lang/en_US.lang
index 31f69d2..a09571c 100644
--- a/src/com/delwink/icebox/lang/en_US.lang
+++ b/src/com/delwink/icebox/lang/en_US.lang
@@ -33,6 +33,11 @@ OrderList.column0=Order #
OrderList.column1=Order Date
OrderList.title=Manage Orders
+QuantityUpdate.column0=Item
+QuantityUpdate.column1=# Sold
+QuantityUpdate.column2=# Waste
+QuantityUpdate.title=New Quantity Update
+
Report.soldVsWaste=Sold vs. Waste
Setting.dialogTitle=Settings
diff --git a/src/com/delwink/icebox/swing/MainWindow.java b/src/com/delwink/icebox/swing/MainWindow.java
index d5dd8ee..b74d57a 100644
--- a/src/com/delwink/icebox/swing/MainWindow.java
+++ b/src/com/delwink/icebox/swing/MainWindow.java
@@ -162,7 +162,17 @@ public class MainWindow extends JFrame {
UPDATE_BUTTON.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
- throw new UnsupportedOperationException("Not supported yet.");
+ QuantityUpdateDialog dialog = new QuantityUpdateDialog(MainWindow.this, INVENTORY);
+
+ dialog.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosed(WindowEvent e) {
+ INVENTORY.refreshQuantities();
+ INVENTORY_TABLE.setModel(new MainWindowTableModel(INVENTORY, REORDER_ONLY.isSelected()));
+ }
+ });
+
+ dialog.setVisible(true);
}
});
diff --git a/src/com/delwink/icebox/swing/QuantityUpdateDialog.java b/src/com/delwink/icebox/swing/QuantityUpdateDialog.java
new file mode 100644
index 0000000..1193eff
--- /dev/null
+++ b/src/com/delwink/icebox/swing/QuantityUpdateDialog.java
@@ -0,0 +1,138 @@
+/*
+ * IceBox - inventory management software for restaurants
+ * Copyright (C) 2016 Delwink, LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, version 3 only.
+ *
+ * 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 Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.delwink.icebox.swing;
+
+import com.delwink.icebox.DataDir;
+import com.delwink.icebox.Inventory;
+import com.delwink.icebox.InventoryItem;
+import com.delwink.icebox.QuantityUpdate;
+import com.delwink.icebox.lang.Lang;
+import com.delwink.icebox.table.QuantityUpdateTableModel;
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+
+/**
+ * A dialog for adding a quantity update.
+ * @author David McMackins II
+ */
+public class QuantityUpdateDialog extends JDialog {
+ private final Inventory INVENTORY;
+ private final JButton ADD_BUTTON, CANCEL_BUTTON, SAVE_BUTTON;
+ private final JComboBox<String> NEW_ITEM_MENU;
+ private final JTable TABLE;
+ private final QuantityUpdate UPDATE;
+
+ public QuantityUpdateDialog(Frame parent, Inventory inventory) {
+ super(parent, Lang.get("QuantityUpdate.title"));
+ setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+ setModal(true);
+
+ INVENTORY = inventory;
+ UPDATE = new QuantityUpdate(new Date());
+
+ TABLE = new JTable(new QuantityUpdateTableModel(UPDATE, INVENTORY));
+ JScrollPane tablePane = new JScrollPane(TABLE);
+
+ final List<Integer> itemIDs = new ArrayList<>();
+ NEW_ITEM_MENU = new JComboBox<>();
+ for (InventoryItem item : new TreeSet<>(inventory.getItems())) {
+ String name = item.getName();
+
+ for (int i = 0; i < NEW_ITEM_MENU.getItemCount(); ++i) {
+ if (NEW_ITEM_MENU.getItemAt(i).equals(name)) {
+ name += " (id=" + item.getID() + ")";
+ break;
+ }
+ }
+
+ NEW_ITEM_MENU.addItem(name);
+ itemIDs.add(item.getID());
+ }
+
+ ADD_BUTTON = new JButton("+");
+ ADD_BUTTON.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ UPDATE.addItem(itemIDs.get(NEW_ITEM_MENU.getSelectedIndex()), 0, 0);
+ TABLE.setModel(new QuantityUpdateTableModel(UPDATE, INVENTORY));
+ }
+ });
+
+ final ActionListener doneEditingListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ };
+
+ CANCEL_BUTTON = new JButton(Lang.get("cancel"));
+ CANCEL_BUTTON.addActionListener(doneEditingListener);
+
+ SAVE_BUTTON = new JButton(Lang.get("save"));
+ SAVE_BUTTON.addActionListener(doneEditingListener);
+ SAVE_BUTTON.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ INVENTORY.addUpdate(UPDATE);
+
+ try (OutputStream os = new FileOutputStream(DataDir.INVENTORY_FILE)) {
+ INVENTORY.saveXml(os);
+ } catch (IOException ex) {
+ Logger.getLogger(QuantityUpdateDialog.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ });
+
+ JPanel buttonBox = new JPanel(new BorderLayout());
+ JPanel leftButtonBox = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ JPanel rightButtonBox = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+
+ leftButtonBox.add(ADD_BUTTON);
+ leftButtonBox.add(NEW_ITEM_MENU);
+ buttonBox.add(leftButtonBox, BorderLayout.WEST);
+
+ rightButtonBox.add(CANCEL_BUTTON);
+ rightButtonBox.add(SAVE_BUTTON);
+ buttonBox.add(rightButtonBox, BorderLayout.EAST);
+
+ setLayout(new BorderLayout());
+ add(tablePane, BorderLayout.CENTER);
+ add(buttonBox, BorderLayout.SOUTH);
+
+ pack();
+ centorOnParent();
+ }
+
+}
diff --git a/src/com/delwink/icebox/table/QuantityUpdateTableModel.java b/src/com/delwink/icebox/table/QuantityUpdateTableModel.java
new file mode 100644
index 0000000..c5600a3
--- /dev/null
+++ b/src/com/delwink/icebox/table/QuantityUpdateTableModel.java
@@ -0,0 +1,99 @@
+/*
+ * IceBox - inventory management software for restaurants
+ * Copyright (C) 2016 Delwink, LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, version 3 only.
+ *
+ * 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 Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.delwink.icebox.table;
+
+import com.delwink.icebox.Inventory;
+import com.delwink.icebox.QuantityUpdate;
+import com.delwink.icebox.lang.Lang;
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * Table model for the quantity update dialog.
+ * @author David McMackins II
+ */
+public class QuantityUpdateTableModel extends AbstractTableModel {
+ private final Inventory INVENTORY;
+ private final QuantityUpdate UPDATE;
+
+ public QuantityUpdateTableModel(QuantityUpdate update, Inventory inventory) {
+ INVENTORY = inventory;
+ UPDATE = update;
+ }
+
+ @Override
+ public int getRowCount() {
+ return UPDATE.getRecords().size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 3;
+ }
+
+ @Override
+ public String getColumnName(int columnIndex) {
+ return Lang.get("QuantityUpdate.column" + columnIndex);
+ }
+
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ return columnIndex == 0 ? String.class : Integer.class;
+ }
+
+ @Override
+ public boolean isCellEditable(int row, int col) {
+ return col >= 1;
+ }
+
+ @Override
+ public Object getValueAt(int row, int col) {
+ QuantityUpdate.Record record = UPDATE.getRecords().get(row);
+
+ switch (col) {
+ case 0:
+ return INVENTORY.getItemByID(record.getItemID()).getName();
+
+ case 1:
+ return record.getSold();
+
+ case 2:
+ return record.getWaste();
+
+ default:
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public void setValueAt(Object o, int row, int col) {
+ QuantityUpdate.Record record = UPDATE.getRecords().get(row);
+
+ switch (col) {
+ case 1:
+ record.setSold((Integer) o);
+ break;
+
+ case 2:
+ record.setWaste((Integer) o);
+ break;
+
+ default:
+ throw new IndexOutOfBoundsException();
+ }
+ }
+}