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;
}
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));
}
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();
}
}
}
Aggregations