Search in sources :

Example 1 with Source

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

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

the class MakeATransactionController method gmCreateSourceBtn.

@FXML
private void gmCreateSourceBtn(ActionEvent event) {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Create Income Source");
    dialog.setHeaderText("Create Income Source, Where from you get Tk.");
    dialog.setContentText("Please type a source name :");
    Stage MakeATransactionStage = (Stage) gmbtnCreateSource.getScene().getWindow();
    dialog.setX(MakeATransactionStage.getX() + 200);
    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 Falied");
            alert.setHeaderText(null);
            alert.setContentText("Write a Source 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 Falied");
            alert.setHeaderText(null);
            alert.setContentText("Write a Source 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 {
            new Source().createSource(typedName);
            Alert confirmationMsg = new Alert(AlertType.INFORMATION);
            confirmationMsg.setTitle("Message");
            confirmationMsg.setHeaderText(null);
            confirmationMsg.setContentText("Source " + typedName + " created successfully");
            Stage SettingsStage = (Stage) MakeATransactionStage.getScene().getWindow();
            confirmationMsg.setX(SettingsStage.getX() + 200);
            confirmationMsg.setY(SettingsStage.getY() + 170);
            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();
            gmLoadSource();
            gmcmboSource.getSelectionModel().selectLast();
        }
    }
}
Also used : Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) KeyFrame(javafx.animation.KeyFrame) EventHandler(javafx.event.EventHandler) Alert(javafx.scene.control.Alert) Source(tab.Source) TextInputDialog(javafx.scene.control.TextInputDialog) FXML(javafx.fxml.FXML)

Example 3 with Source

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

the class GetMoneyChart method getSourceData.

public static Series<String, Number> getSourceData(String monthName) {
    XYChart.Series<String, Number> source = new XYChart.Series<>();
    String[] allSource = new ComboboxList().getSourceListForDashboard();
    for (String sourceName : allSource) {
        if (!sourceName.equals("All")) {
            if (sourceName.equals("Carried Over Amount")) {
                String sourceShortName = getAbbreviateName(sourceName);
                double amount = longToDouble(new CarriedOver().getCOAmount(monthName));
                source.getData().add(new XYChart.Data<>(sourceShortName, amount));
            } else {
                String sourceShortName = getAbbreviateName(sourceName);
                double amount = longToDouble(new Source().getAmountBySourceFromGM(monthName, sourceName));
                source.getData().add(new XYChart.Data<>(sourceShortName, amount));
            }
        }
    }
    return source;
}
Also used : Series(javafx.scene.chart.XYChart.Series) CarriedOver(operation.CarriedOver) ComboboxList(operation.ComboboxList) XYChart(javafx.scene.chart.XYChart) Source(tab.Source)

Aggregations

Source (tab.Source)3 CarriedOver (operation.CarriedOver)2 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