View Javadoc
1   /*
2    * Copyright (c) Patrick Magauran 2018.
3    *   Licensed under the AGPLv3. All conditions of said license apply.
4    *       This file is part of ABOS.
5    *
6    *       ABOS is free software: you can redistribute it and/or modify
7    *       it under the terms of the GNU Affero General Public License as published by
8    *       the Free Software Foundation, either version 3 of the License, or
9    *       (at your option) any later version.
10   *
11   *       ABOS is distributed in the hope that it will be useful,
12   *       but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *       GNU Affero General Public License for more details.
15   *
16   *       You should have received a copy of the GNU Affero General Public License
17   *       along with ABOS.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package Controllers;
21  
22  import Utilities.Order;
23  import Utilities.Year;
24  import Utilities.formattedProduct;
25  import Utilities.formattedProductProps;
26  import javafx.collections.FXCollections;
27  import javafx.collections.ObservableList;
28  import javafx.event.ActionEvent;
29  import javafx.fxml.FXML;
30  import javafx.scene.control.Label;
31  import javafx.scene.control.TableColumn;
32  import javafx.scene.control.TableView;
33  import javafx.scene.control.cell.PropertyValueFactory;
34  import javafx.scene.layout.VBox;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  import java.util.Objects;
39  
40  //import javax.swing.*;
41  @SuppressWarnings("WeakerAccess")
42  
43  public class YearController {
44  
45      public static String year = "2017";
46      @FXML
47      private TableView yearOrders;
48      @FXML
49      private VBox yearInfo;
50      private Boolean columnsFilled = false;
51      private String uName;
52  
53  // --Commented out by Inspection START (1/2/2016 12:01 PM):
54  //    /**
55  //     * Launch the application.
56  //     */
57  //    public static void main(String Years, String[] args) {
58  //        EventQueue.invokeLater(new Runnable() {
59  //            public void run() {
60  //                try {
61  //                    year = Years;
62  //                    Utilities.Year window = new Utilities.Year(Years);
63  //                    window.frame.setVisible(true);
64  //                } catch (Exception e) {
65  //                    e.printStackTrace();
66  //                }
67  //            }
68  //        });
69  //    }
70  // --Commented out by Inspection STOP (1/2/2016 12:01 PM)
71  
72      /**
73       * Initialize the contents of the frame.
74       */
75      public void initYear(String Years) {
76          this.initYear(Years, "");
77      }
78  
79      /**
80       * Initialize the contents of the frame.
81       */
82      public void initYear(String Years, String userName) {
83          year = Years;
84          uName = userName;
85          Year yearDbInfo = new Year(year, userName);
86          yearInfo.getChildren().removeAll();
87          //West
88  
89          VBox East = new VBox();
90          List<infoValPair> yearInfoStrings = new ArrayList<>();
91          yearInfoStrings.add(new infoValPair("Customers", Integer.toString(yearDbInfo.getNoCustomers())));
92          //yearDbInfo.getCategories().forEach(category -> yearInfoStrings.add(new infoValPair(category.catName + " Products", Integer.toString(yearDbInfo.getLG()))));
93          /*yearInfoStrings.add(new infoValPair("Lawn and Garden Products", Integer.toString(yearDbInfo.getLG())));
94          yearInfoStrings.add(new infoValPair("Live Plant Products", Integer.toString(yearDbInfo.getLP())));
95          yearInfoStrings.add(new infoValPair("Mulch", Integer.toString(yearDbInfo.getMulch())));*/
96          yearInfoStrings.add(new infoValPair("Order Total", yearDbInfo.getOT().toPlainString()));
97          yearInfoStrings.add(new infoValPair("Donations", yearDbInfo.getDonations().toPlainString()));
98          yearInfoStrings.add(new infoValPair("Grand Total", yearDbInfo.getGTot().toPlainString()));
99          yearInfoStrings.add(new infoValPair("Commission", yearDbInfo.getCommis().toPlainString()));
100 
101 
102         yearInfoStrings.forEach((pair) -> {
103             Label keyLabel = new Label(pair.info + ":");
104             Label valLabel = new Label(pair.value);
105             keyLabel.setId("YearDescription");
106             valLabel.setId("YearValue");
107             VBox info = new VBox(keyLabel, valLabel);
108             info.getStyleClass().add("informationPane");
109             yearInfo.getChildren().add(info);
110         });
111 
112 
113         fillTable();
114     }
115 
116     public void initialize() {
117 
118     }
119 
120     @FXML
121     public void refresh(ActionEvent event) {
122         initialize();
123     }
124 
125 /*    @FXML
126     public void deleteYear(ActionEvent event) {
127         Utilities.Year yearObj = new Utilities.Year(year);
128         yearObj.deleteYear();
129         mainController.fillTreeView();
130 
131     }
132 
133     @FXML
134     public void editYear(ActionEvent event) {
135         new Launchers.AddYear(year, mainController.getWindow());
136     }*/
137 
138     /**
139      * Fills the Table of order amounts
140      */
141     private void fillTable() {
142         Order.orderArray order;
143         if (Objects.equals(uName, "")) {
144             order = Order.createOrderArray(year, "");
145 
146         } else {
147             order = Order.createOrderArray(year, uName);
148 
149         }
150         ObservableList<formattedProductProps> data = FXCollections.observableArrayList();
151 
152         int i = 0;
153         for (formattedProduct productOrder : order.orderData) {
154             //String productID, String productName, String productSize, String productUnitPrice, String productCategory, int orderedQuantity, BigDecimal extendedCost
155             formattedProductProps prodProps = new formattedProductProps(productOrder.productKey, productOrder.productID, productOrder.productName, productOrder.productSize, productOrder.productUnitPrice, productOrder.productCategory, productOrder.orderedQuantity, productOrder.extendedCost);
156             data.add(prodProps);
157             i++;
158         }
159         if (!columnsFilled) {
160             String[][] columnNames = {{"Item", "productName"}, {"Size", "productSize"}, {"Price/Item", "productUnitPrice"}, {"Quantity", "orderedQuantity"}, {"Price", "extendedCost"}};
161             for (String[] column : columnNames) {
162                 TableColumn<formattedProductProps, String> tbCol = new TableColumn<>(column[0]);
163                 tbCol.setCellValueFactory(new PropertyValueFactory<>(column[1]));
164                 yearOrders.getColumns().add(tbCol);
165             }
166         }
167         columnsFilled = true;
168 
169 
170         yearOrders.setItems(data);
171         yearOrders.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
172     }
173 
174     private class infoValPair {
175         public String info;
176         public String value;
177 
178         public infoValPair(String inf, String val) {
179             this.info = inf;
180             this.value = val;
181         }
182     }
183 
184 }
185