private double getThisWeeksOrdersCost() { double totalCost = 0.0; for (PurchasingTransaction order : database.getPurchasingTransactions()) { if (isDateInCurrentWeek(order.getTransactionDate())) totalCost += order.getTransactionCost(); } return totalCost; }
// update content on panel when a new order is added to the system public void newOrderAdded() { lblOrdersThisWeek.setText(getNoOrdersThisWeek() + ""); lblTotalOrders.setText(database.getPurchasingTransactions().size() + ""); lblWeeksCost.setText(String.format("€%.2f", getThisWeeksOrdersCost())); lblTotalCost.setText(String.format("€%.2f", getTotalCostOfOrders())); refreshCharts(); }
private double getTotalCostOfOrders() { double totalCost = 0.0; for (PurchasingTransaction order : database.getPurchasingTransactions()) { totalCost += order.getTransactionCost(); } return totalCost; }
private double getPercentCostThisWeek() { double weeksCost = 0.0; double totalCost = 0.0; for (PurchasingTransaction order : database.getPurchasingTransactions()) { if (isDateInCurrentWeek(order.getTransactionDate())) { weeksCost += order.getTransactionCost(); } totalCost += order.getTransactionCost(); } return (double) weeksCost / totalCost * 100; }
private double getPercentEarlierCost() { double totalCost = 0.0; double earlierCost = 0.0; for (PurchasingTransaction order : database.getPurchasingTransactions()) { if (!isDateInCurrentWeek(order.getTransactionDate())) { earlierCost += order.getTransactionCost(); } totalCost += order.getTransactionCost(); } return (double) earlierCost / totalCost * 100; }
private void setNumberChartContent() { // get values for numbers data set int totalOrders = database.getPurchasingTransactions().size(); int difference = totalOrders - ordersThisWeek; double percentEarlierOrders = (double) difference / totalOrders * 100; double percentThisWeek = (double) ordersThisWeek / totalOrders * 100; // set up pie chart that displays proportions of orders this week PieDataset dataSet = createChartDataSet( percentEarlierOrders, percentThisWeek, "Earlier orders", "Orders this week"); numbersChart = createPieChart(dataSet, "Proportions of orders this week"); }
private int getNoOrdersThisWeek() { int noOrders = 0; // set start of week object to preceding Monday at 00:00:00 Calendar startOfWeek = Calendar.getInstance(); startOfWeek.set(Calendar.DAY_OF_YEAR, (Calendar.DAY_OF_YEAR - Calendar.DAY_OF_WEEK)); for (PurchasingTransaction order : database.getPurchasingTransactions()) { if (isDateInCurrentWeek(order.getTransactionDate())) { noOrders++; } } ordersThisWeek = noOrders; return noOrders; }
private void setUpTxtPanelLabels() { totalOrdersLabel = new JLabel("Total number of orders in system:", JLabel.CENTER); thisWeeksOrdersLabel = new JLabel("Number of orders this week:", JLabel.CENTER); totalCostLabel = new JLabel("Total cost of orders in system:", JLabel.CENTER); weeksCostLabel = new JLabel("Cost of this weeks orders:", JLabel.CENTER); totalOrdersLabel.setOpaque(true); totalOrdersLabel.setBackground(new Color(107, 106, 104)); totalOrdersLabel.setForeground(Color.WHITE); thisWeeksOrdersLabel.setBackground(new Color(107, 106, 104)); thisWeeksOrdersLabel.setForeground(Color.WHITE); thisWeeksOrdersLabel.setOpaque(true); totalCostLabel.setBackground(new Color(107, 106, 104)); totalCostLabel.setForeground(Color.WHITE); totalCostLabel.setOpaque(true); weeksCostLabel.setBackground(new Color(107, 106, 104)); weeksCostLabel.setForeground(Color.WHITE); weeksCostLabel.setOpaque(true); lblTotalOrders = new JLabel(database.getPurchasingTransactions().size() + "", JLabel.CENTER); lblOrdersThisWeek = new JLabel(getNoOrdersThisWeek() + "", JLabel.CENTER); lblTotalCost = new JLabel(String.format("€%.2f", getTotalCostOfOrders()), JLabel.CENTER); lblWeeksCost = new JLabel(String.format("€%.2f", getThisWeeksOrdersCost()), JLabel.CENTER); lblTotalOrders.setBackground(Color.LIGHT_GRAY); lblTotalOrders.setOpaque(true); lblOrdersThisWeek.setBackground(Color.LIGHT_GRAY); lblOrdersThisWeek.setOpaque(true); lblTotalCost.setBackground(Color.LIGHT_GRAY); lblTotalCost.setOpaque(true); lblWeeksCost.setBackground(Color.LIGHT_GRAY); lblWeeksCost.setOpaque(true); // add labels to panel txtPanel.add(totalOrdersLabel); txtPanel.add(lblTotalOrders); txtPanel.add(thisWeeksOrdersLabel); txtPanel.add(lblOrdersThisWeek); txtPanel.add(totalCostLabel); txtPanel.add(lblTotalCost); txtPanel.add(weeksCostLabel); txtPanel.add(lblWeeksCost); }