Search in sources :

Example 1 with Sector

use of tab.Sector 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 2 with Sector

use of tab.Sector 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 3 with Sector

use of tab.Sector in project Money-Manager by krHasan.

the class MakeATransactionController method exCreateSectorBtn.

// function for creating a sector
@FXML
private void exCreateSectorBtn(ActionEvent event) {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Create Sector");
    dialog.setHeaderText("Create your expenditure sector, where you expense Tk.");
    dialog.setContentText("Please Type a Name :");
    Stage MakeATransactionStage = (Stage) exbtnCreateSector.getScene().getWindow();
    dialog.setX(MakeATransactionStage.getX() + 150);
    dialog.setY(MakeATransactionStage.getY() + 170);
    Optional<String> result = dialog.showAndWait();
    if (result.isPresent()) {
        String typedName = result.get();
        if (typedName.length() == 0) {
            Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Operation Failed");
            alert.setHeaderText(null);
            alert.setContentText("Write a Sector Name Please");
            alert.setX(MakeATransactionStage.getX() + 200);
            alert.setY(MakeATransactionStage.getY() + 170);
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    alert.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            alert.showAndWait();
        } else if (countWords(typedName) == 0) {
            Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Operation Failed");
            alert.setHeaderText(null);
            alert.setContentText("Write a Sector Name Please");
            alert.setX(MakeATransactionStage.getX() + 200);
            alert.setY(MakeATransactionStage.getY() + 170);
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    alert.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            alert.showAndWait();
        } else if (new Sector().createSector(typedName)) {
            Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Operation Failed");
            alert.setHeaderText(null);
            alert.setContentText("Sector Name Already Exist");
            alert.setX(MakeATransactionStage.getX() + 200);
            alert.setY(MakeATransactionStage.getY() + 170);
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    alert.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            alert.showAndWait();
        } else {
            new Sector().createSector(typedName);
            Alert confirmationMsg = new Alert(AlertType.INFORMATION);
            confirmationMsg.setTitle("Message");
            confirmationMsg.setHeaderText(null);
            confirmationMsg.setContentText("Sector " + typedName + " created successfully");
            confirmationMsg.setX(MakeATransactionStage.getX() + 200);
            confirmationMsg.setY(MakeATransactionStage.getY() + 170);
            Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    confirmationMsg.hide();
                }
            }));
            idlestage.setCycleCount(1);
            idlestage.play();
            confirmationMsg.showAndWait();
            exLoadSector();
            excmboSector.getSelectionModel().selectLast();
        }
    }
}
Also used : Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) Sector(tab.Sector) Stage(javafx.stage.Stage) KeyFrame(javafx.animation.KeyFrame) EventHandler(javafx.event.EventHandler) Alert(javafx.scene.control.Alert) TextInputDialog(javafx.scene.control.TextInputDialog) FXML(javafx.fxml.FXML)

Aggregations

Sector (tab.Sector)3 ComboboxList (operation.ComboboxList)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 FXML (javafx.fxml.FXML)1 XYChart (javafx.scene.chart.XYChart)1 Series (javafx.scene.chart.XYChart.Series)1 Alert (javafx.scene.control.Alert)1 TextInputDialog (javafx.scene.control.TextInputDialog)1 Stage (javafx.stage.Stage)1