Search in sources :

Example 1 with Expense

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

the class MakeATransactionController method exbtnAdvancedAdjustBalance.

@FXML
private void exbtnAdvancedAdjustBalance(ActionEvent event) {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Adjust Wallet Balance");
    dialog.setHeaderText("Provide Balance Status at Your Hand Now.");
    dialog.setContentText("Please enter the amount:");
    Stage MakeATransactionStage = (Stage) exbtnAdjustBalance.getScene().getWindow();
    dialog.setX(MakeATransactionStage.getX() + 200);
    dialog.setY(MakeATransactionStage.getY() + 170);
    Optional<String> result = dialog.showAndWait();
    if (result.isPresent()) {
        String typedAmount = result.get();
        if (!validAmount(typedAmount)) {
            Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Transaction Failed");
            alert.setHeaderText(null);
            alert.setContentText(InvalidInput);
            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();
        } else if (amountIsZero(typedAmount)) {
            Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Transaction Failed");
            alert.setHeaderText(null);
            alert.setContentText("Zero is not approved.");
            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();
        } else {
            long dbWalletBalance = currentWalletBalance();
            long typedBalance = stringToLong(typedAmount);
            String exAdvAdjustBalAfter = typedAmount;
            String exAdvAdjustAmount;
            if (dbWalletBalance < typedBalance) {
                exAdvAdjustAmount = "added " + longToString(typedBalance - dbWalletBalance) + " to Wallet";
            } else if (dbWalletBalance > typedBalance) {
                exAdvAdjustAmount = exWalletBalanceAfter(typedAmount);
            } else {
                exAdvAdjustAmount = "0.0";
            }
            try {
                Map<String, String> expenseData = new HashMap<>();
                expenseData.put("exTime", timeToSave());
                expenseData.put("exDate", (new DateFormatManager()).toString(exdateAdvancedDate.getValue()));
                expenseData.put("exMonth", monthToSave(exdateAdvancedDate.getValue()));
                expenseData.put("exAmount", exAdvAdjustAmount);
                if (exIsAdvDescripionEmpty()) {
                    expenseData.put("exDescription", "You have adjusted your Wallet Balance");
                } else {
                    expenseData.put("exDescription", extxtAdvancedDescription.getText());
                }
                expenseData.put("exSector", "Adjusted Balance");
                expenseData.put("exWalletBalanceBefore", getWalletBalance());
                expenseData.put("exWalletBalanceAfter", exAdvAdjustBalAfter);
                setCurrentWalletBalance(exAdvAdjustBalAfter);
                (new Expense()).saveExpenseData(expenseData);
                (new ComboboxList()).setAllMonth(monthToSave(exdateAdvancedDate.getValue()), yearToSave(exdateAdvancedDate.getValue()));
                (new ComboboxList()).setAllExMonth(monthToSave(exdateAdvancedDate.getValue()), yearToSave(exdateAdvancedDate.getValue()));
                exInitialize();
                extxtAdvancedDescription.clear();
                Alert confirmationMsg = new Alert(AlertType.INFORMATION);
                confirmationMsg.setTitle("Successfull Transaction");
                confirmationMsg.setHeaderText(null);
                confirmationMsg.setContentText("Successful");
                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.");
                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();
            }
        }
    }
}
Also used : 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) Map(java.util.Map) HashMap(java.util.HashMap) TextInputDialog(javafx.scene.control.TextInputDialog) FXML(javafx.fxml.FXML)

Example 2 with Expense

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

the class MakeATransactionController method exAdvSaveFunction.

private void exAdvSaveFunction(String amount, String sectorName) {
    try {
        Map<String, String> expenseData = new HashMap<>();
        expenseData.put("exTime", timeToSave());
        expenseData.put("exDate", (new DateFormatManager()).toString(exdateAdvancedDate.getValue()));
        expenseData.put("exMonth", monthToSave(exdateAdvancedDate.getValue()));
        expenseData.put("exAmount", amount);
        if (exIsAdvDescripionEmpty()) {
            expenseData.put("exDescription", "None");
        } else {
            expenseData.put("exDescription", extxtAdvancedDescription.getText());
        }
        expenseData.put("exSector", sectorName);
        expenseData.put("exWalletBalanceBefore", getWalletBalance());
        expenseData.put("exWalletBalanceAfter", exWalletBalanceAfter(amount));
        setCurrentWalletBalance(exWalletBalanceAfter(amount));
        (new Expense()).saveExpenseData(expenseData);
        (new ComboboxList()).setAllMonth(monthToSave(exdateAdvancedDate.getValue()), yearToSave(exdateAdvancedDate.getValue()));
        (new ComboboxList()).setAllExMonth(monthToSave(exdateAdvancedDate.getValue()), yearToSave(exdateAdvancedDate.getValue()));
    } catch (Exception e) {
    }
}
Also used : HashMap(java.util.HashMap) Expense(tab.Expense) ComboboxList(operation.ComboboxList) DateFormatManager(system.DateFormatManager)

Example 3 with Expense

use of tab.Expense 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

HashMap (java.util.HashMap)3 ComboboxList (operation.ComboboxList)3 DateFormatManager (system.DateFormatManager)3 Expense (tab.Expense)3 KeyFrame (javafx.animation.KeyFrame)2 Timeline (javafx.animation.Timeline)2 ActionEvent (javafx.event.ActionEvent)2 EventHandler (javafx.event.EventHandler)2 Alert (javafx.scene.control.Alert)2 Stage (javafx.stage.Stage)2 Map (java.util.Map)1 FXML (javafx.fxml.FXML)1 TextInputDialog (javafx.scene.control.TextInputDialog)1