Search in sources :

Example 6 with ComboboxList

use of operation.ComboboxList in project Money-Manager by krHasan.

the class SettingsController method advancedBtnAdd.

@FXML
private void advancedBtnAdd(ActionEvent event) {
    try {
        if (new ComboboxList().getAdvancedSectorActiveArraySize() == 7) {
            Alert confirmationMsg = new Alert(AlertType.INFORMATION);
            confirmationMsg.setTitle("Message");
            confirmationMsg.setHeaderText(null);
            confirmationMsg.setContentText("You can add maximum 7 sector to this list");
            Stage SettingsStage = (Stage) btnDashboard.getScene().getWindow();
            confirmationMsg.setX(SettingsStage.getX() + 200);
            confirmationMsg.setY(SettingsStage.getY() + 170);
            tabAdvancedInitialize();
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(7), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    confirmationMsg.setResult(ButtonType.CANCEL);
                    confirmationMsg.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            confirmationMsg.showAndWait();
        } else {
            advancedSector.addSectorToList(advancedCmboAdd.getValue());
            Alert confirmationMsg = new Alert(AlertType.INFORMATION);
            confirmationMsg.setTitle("Message");
            confirmationMsg.setHeaderText(null);
            confirmationMsg.setContentText("Successful");
            Stage SettingsStage = (Stage) btnDashboard.getScene().getWindow();
            confirmationMsg.setX(SettingsStage.getX() + 200);
            confirmationMsg.setY(SettingsStage.getY() + 28);
            tabAdvancedInitialize();
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(2), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    confirmationMsg.setResult(ButtonType.CANCEL);
                    confirmationMsg.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            confirmationMsg.showAndWait();
        }
    } catch (Exception e) {
    }
}
Also used : Timeline(javafx.animation.Timeline) ComboboxList(operation.ComboboxList) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) KeyFrame(javafx.animation.KeyFrame) EventHandler(javafx.event.EventHandler) Alert(javafx.scene.control.Alert) FXML(javafx.fxml.FXML)

Example 7 with ComboboxList

use of operation.ComboboxList in project Money-Manager by krHasan.

the class ExpenseChart method getExpenseData.

public static Series<String, Number> getExpenseData(String monthName) {
    XYChart.Series<String, Number> sector = new XYChart.Series<>();
    String[] allSector = new ComboboxList().getSectorList();
    // chart data for all other Sectors
    for (String sectorName : allSector) {
        String sectorShortName = getAbbreviateName(sectorName);
        double amount = longToDouble(new Sector().getAmountBySectorFromExpense(monthName, sectorName));
        sector.getData().add(new XYChart.Data<>(sectorShortName, amount));
    }
    // chart data for "Adjusted Balance" Sector
    String srtName = getAbbreviateName("Adjusted Balance");
    double amnt = longToDouble(new Sector().getAmountBySectorFromExpense(monthName, "Adjusted Balance"));
    sector.getData().add(new XYChart.Data<>(srtName, amnt));
    return sector;
}
Also used : Series(javafx.scene.chart.XYChart.Series) ComboboxList(operation.ComboboxList) Sector(tab.Sector) XYChart(javafx.scene.chart.XYChart)

Example 8 with ComboboxList

use of operation.ComboboxList in project Money-Manager by krHasan.

the class DashboardModel method getAmountBySector.

public String getAmountBySector(String monthName, String sectorName) {
    long totalAmountinLong = 0;
    if (monthName.equals("Total")) {
        if (sectorName.equals("All")) {
            String allExpenseSql = "SELECT exAmount FROM Expense WHERE exSector <> \"Adjusted Balance\"";
            try (Connection conn = connector();
                Statement stmt = conn.createStatement();
                ResultSet result = stmt.executeQuery(allExpenseSql)) {
                while (result.next()) {
                    totalAmountinLong += UnitConverter.stringToLong(removeThousandSeparator(result.getString("exAmount")));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            long totalAdjustBal = 0;
            String allAdjustBalSql = "SELECT exAmount FROM Expense WHERE exSector = \"Adjusted Balance\"";
            try (Connection conn = connector();
                Statement stmt = conn.createStatement();
                ResultSet result = stmt.executeQuery(allAdjustBalSql)) {
                while (result.next()) {
                    totalAdjustBal += UnitConverter.stringToLong(removeThousandSeparator(result.getString("exAmount").replaceAll("[^0-9.*]", "")));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            totalAmountinLong = totalAmountinLong - totalAdjustBal;
        } else if (sectorName.equals("Adjusted Balance")) {
            String sql = "SELECT exAmount FROM Expense WHERE exSector = \"Adjusted Balance\"";
            try (Connection conn = connector();
                Statement stmt = conn.createStatement();
                ResultSet result = stmt.executeQuery(sql)) {
                long totalAddedBal = 0;
                while (result.next()) {
                    if (result.getString("exAmount").matches(".*\\badded\\b.*")) {
                        totalAddedBal += stringToLong(removeThousandSeparator(result.getString("exAmount").replaceAll("[^0-9.*]", "")));
                    } else {
                        totalAmountinLong += stringToLong(removeThousandSeparator(result.getString("exAmount")));
                    }
                }
                totalAmountinLong = totalAmountinLong - totalAddedBal;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            String bysectorSql = "SELECT exAmount FROM Expense WHERE exSector = ? ";
            try (Connection conn = connector();
                PreparedStatement pstmt = conn.prepareStatement(bysectorSql)) {
                pstmt.setString(1, sectorName);
                ResultSet result = pstmt.executeQuery();
                while (result.next()) {
                    totalAmountinLong += UnitConverter.stringToLong(removeThousandSeparator(result.getString("exAmount")));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        if (sectorName.equals("All")) {
            totalAmountinLong += new Sector().getAmountBySectorFromExpense(monthName, "Adjusted Balance");
            String[] sectorList = new ComboboxList().getSectorList();
            for (String string : sectorList) {
                totalAmountinLong += new Sector().getAmountBySectorFromExpense(monthName, string);
            }
            totalAmountinLong -= new Sector().addedAdjustBalance(monthName);
        } else {
            totalAmountinLong = new Sector().getAmountBySectorFromExpense(monthName, sectorName);
        }
    }
    return addThousandSeparator(longToString(totalAmountinLong));
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Sector(tab.Sector) ComboboxList(operation.ComboboxList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 9 with ComboboxList

use of operation.ComboboxList in project Money-Manager by krHasan.

the class DashboardModel method getAmountBySource.

public String getAmountBySource(String monthName, String sourceName) {
    long totalAmountinLong = 0;
    if (monthName.equals("Total")) {
        if (sourceName.equals("All")) {
            String allGetMoneySql = "SELECT gmAmount FROM Get_Money";
            try (Connection conn = connector();
                Statement stmt = conn.createStatement();
                ResultSet result = stmt.executeQuery(allGetMoneySql)) {
                while (result.next()) {
                    totalAmountinLong += UnitConverter.stringToLong(removeThousandSeparator(result.getString("gmAmount")));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (sourceName.equals("Carried Over Amount")) {
            totalAmountinLong = 0;
        } else {
            String sql = "SELECT gmAmount FROM Get_Money WHERE gmSource = ?";
            try (Connection conn = connector();
                PreparedStatement pstmt = conn.prepareStatement(sql)) {
                pstmt.setString(1, sourceName);
                ResultSet result = pstmt.executeQuery();
                while (result.next()) {
                    totalAmountinLong += UnitConverter.stringToLong(removeThousandSeparator(result.getString("gmAmount")));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        if (sourceName.equals("All")) {
            String[] sourceList = new ComboboxList().getSourceListForDashboard();
            for (String string : sourceList) {
                totalAmountinLong += new Source().getAmountBySourceFromGM(monthName, string);
            }
            totalAmountinLong += new CarriedOver().getCOAmount(monthName);
        } else if (sourceName.equals("Carried Over Amount")) {
            totalAmountinLong = new CarriedOver().getCOAmount(monthName);
        } else {
            totalAmountinLong = new Source().getAmountBySourceFromGM(monthName, sourceName);
        }
    }
    return addThousandSeparator(longToString(totalAmountinLong));
}
Also used : CarriedOver(operation.CarriedOver) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ComboboxList(operation.ComboboxList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Source(tab.Source)

Example 10 with ComboboxList

use of operation.ComboboxList in project Money-Manager by krHasan.

the class MakeATransactionController method exSaveFunction.

// save user input values to database
private void exSaveFunction() {
    try {
        Map<String, String> expenseData = new HashMap<>();
        expenseData.put("exTime", timeToSave());
        expenseData.put("exDate", (new DateFormatManager()).toString(exdateDate.getValue()));
        expenseData.put("exMonth", monthToSave(exdateDate.getValue()));
        if (adjustBtnPressed) {
            expenseData.put("exAmount", exAdjustAmount);
        } else {
            expenseData.put("exAmount", extxtAmount.getText());
        }
        if (adjustBtnPressed) {
            if (exIsDescripionEmpty()) {
                expenseData.put("exDescription", "You have adjusted your Wallet Balance");
            } else {
                expenseData.put("exDescription", extxtDescription.getText());
            }
        } else {
            if (exIsDescripionEmpty()) {
                expenseData.put("exDescription", "None");
            } else {
                expenseData.put("exDescription", extxtDescription.getText());
            }
        }
        if (adjustBtnPressed) {
            expenseData.put("exSector", "Adjusted Balance");
        } else {
            expenseData.put("exSector", excmboSector.getValue());
        }
        expenseData.put("exWalletBalanceBefore", getWalletBalance());
        if (adjustBtnPressed) {
            expenseData.put("exWalletBalanceAfter", exAdjustBalAfter);
            setCurrentWalletBalance(exAdjustBalAfter);
        } else {
            expenseData.put("exWalletBalanceAfter", exWalletBalanceAfter(extxtAmount.getText()));
            setCurrentWalletBalance(exWalletBalanceAfter(extxtAmount.getText()));
        }
        (new Expense()).saveExpenseData(expenseData);
        (new ComboboxList()).setAllMonth(monthToSave(exdateDate.getValue()), yearToSave(exdateDate.getValue()));
        (new ComboboxList()).setAllExMonth(monthToSave(exdateDate.getValue()), yearToSave(exdateDate.getValue()));
        exInitialize();
        extxtAmount.clear();
        extxtDescription.clear();
        Alert confirmationMsg = new Alert(AlertType.INFORMATION);
        confirmationMsg.setTitle("Successfull Transaction");
        confirmationMsg.setHeaderText(null);
        confirmationMsg.setContentText("Successful");
        Stage MakeATransactionStage = (Stage) exbtnSave.getScene().getWindow();
        confirmationMsg.setX(MakeATransactionStage.getX() + 200);
        confirmationMsg.setY(MakeATransactionStage.getY() + 29);
        Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(2), new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                confirmationMsg.hide();
            }
        }));
        idlestage.setCycleCount(1);
        idlestage.play();
        confirmationMsg.showAndWait();
    } catch (Exception e) {
        Alert alert = new Alert(AlertType.WARNING);
        alert.setTitle("Transaction Failed");
        alert.setHeaderText(null);
        alert.setContentText("There something is wrong.");
        Stage MakeATransactionStage = (Stage) exbtnSave.getScene().getWindow();
        alert.setX(MakeATransactionStage.getX() + 200);
        alert.setY(MakeATransactionStage.getY() + 170);
        Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(2), new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                alert.hide();
            }
        }));
        idlestage.setCycleCount(1);
        idlestage.play();
        alert.showAndWait();
    }
}
Also used : HashMap(java.util.HashMap) ActionEvent(javafx.event.ActionEvent) DateFormatManager(system.DateFormatManager) EventHandler(javafx.event.EventHandler) Timeline(javafx.animation.Timeline) Expense(tab.Expense) ComboboxList(operation.ComboboxList) Stage(javafx.stage.Stage) KeyFrame(javafx.animation.KeyFrame) Alert(javafx.scene.control.Alert)

Aggregations

ComboboxList (operation.ComboboxList)16 Stage (javafx.stage.Stage)8 HashMap (java.util.HashMap)7 KeyFrame (javafx.animation.KeyFrame)7 Timeline (javafx.animation.Timeline)7 ActionEvent (javafx.event.ActionEvent)7 EventHandler (javafx.event.EventHandler)7 Alert (javafx.scene.control.Alert)7 DateFormatManager (system.DateFormatManager)7 FXML (javafx.fxml.FXML)6 Bkash (tab.Bkash)4 Rocket (tab.Rocket)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 CarriedOver (operation.CarriedOver)3 Expense (tab.Expense)3 GetMoney (tab.GetMoney)3 Statement (java.sql.Statement)2 XYChart (javafx.scene.chart.XYChart)2