diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 524d642..210b5af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,32 +1,32 @@ -name: JavaFX Build (Gradle) - -on: - push: - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 17 - cache: gradle - - - name: Make Gradle executable - run: chmod +x gradlew - - - name: Build using Gradle - run: ./gradlew clean build --exclude-task spotlessCheck - - - name: Upload JAR artifact - uses: actions/upload-artifact@v4 - with: - name: satyam-consignment +name: JavaFX Build (Gradle) + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: gradle + + - name: Make Gradle executable + run: chmod +x gradlew + + - name: Build using Gradle + run: ./gradlew clean build + + - name: Upload JAR artifact + uses: actions/upload-artifact@v4 + with: + name: satyam-consignment path: build/libs/* \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4a7fa42..9ae78ab 100644 --- a/build.gradle +++ b/build.gradle @@ -1,102 +1,107 @@ -plugins { - id 'application' - id 'java' - id "org.openjfx.javafxplugin" version "0.1.0" - id 'com.diffplug.spotless' version '7.0.2' - id "com.github.johnrengelman.shadow" version "7.1.2" -} - -repositories { - mavenCentral() -} - -dependencies { - implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.2.2' - implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.1.0' - implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.34.0' - implementation group: 'org.olap4j', name: 'olap4j', version: '1.2.0' - implementation group: 'com.lowagie', name: 'itext', version: '2.1.7' - - implementation("org.openjfx:javafx-controls:17") - implementation("org.openjfx:javafx-base:17") - implementation("org.openjfx:javafx-graphics:17") - implementation("org.openjfx:javafx-fxml:17") - - compileOnly 'org.projectlombok:lombok:1.18.20' - annotationProcessor 'org.projectlombok:lombok:1.18.20' - - testCompileOnly 'org.projectlombok:lombok:1.18.20' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.20' - - testImplementation 'org.testfx:testfx-junit5:4.0.18' - testImplementation 'org.testfx:openjfx-monocle:17.0.10' - testImplementation 'org.hamcrest:hamcrest:2.2' - - testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.1" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1" - - testImplementation "org.testfx:testfx-core:4.0.17" -} - -javafx { - version = "17" - modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics', 'javafx.base' ] -} - -test { - useJUnitPlatform() - - if (System.getenv("CI") == "true") { - jvmArgs = [ - "-Dtestfx.robot=glass", - "-Dtestfx.headless=true", - "-Dprism.order=sw", - "-Dprism.text=t2k", - "-Djava.awt.headless=true" - ] - } -} - -spotless { - java { - lineEndings 'WINDOWS' - target 'src/**/*.java' - eclipse().configFile('spotless.eclipseformat.xml') - removeUnusedImports() - } -} - -mainClassName = 'satyamconsignment.Launcher' - -application { - mainClassName = mainClassName -} - -run { - jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED'] - jvmArgs += ['--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED'] - jvmArgs += ['--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED'] - jvmArgs += ['--add-exports=javafx.base/com.sun.javafx.binding=ALL-UNNAMED'] - jvmArgs += ['--add-exports=javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED'] -} - -shadowJar { - archiveClassifier.set("") -} - -tasks.register('copyScripts', Copy) { - from('scripts') { - include 'start.sh' - include 'start.bat' - } - into "${layout.buildDirectory.get()}/libs" - doLast { - println "Copied scripts to build directory" - } -} - -tasks.named('shadowJar') { - dependsOn ( - tasks.named('copyScripts') - ) -} +import com.diffplug.spotless.LineEnding + +plugins { + id 'application' + id 'java' + id "org.openjfx.javafxplugin" version "0.1.0" + id 'com.diffplug.spotless' version '7.0.2' + id "com.github.johnrengelman.shadow" version "7.1.2" +} + +repositories { + mavenCentral() +} + +dependencies { + implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.2.2' + implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.1.0' + implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.34.0' + implementation group: 'org.olap4j', name: 'olap4j', version: '1.2.0' + implementation group: 'com.lowagie', name: 'itext', version: '2.1.7' + + implementation("org.openjfx:javafx-controls:17") + implementation("org.openjfx:javafx-base:17") + implementation("org.openjfx:javafx-graphics:17") + implementation("org.openjfx:javafx-fxml:17") + + compileOnly 'org.projectlombok:lombok:1.18.20' + annotationProcessor 'org.projectlombok:lombok:1.18.20' + + testCompileOnly 'org.projectlombok:lombok:1.18.20' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.20' + + testImplementation 'org.testfx:testfx-junit5:4.0.18' + testImplementation 'org.testfx:openjfx-monocle:17.0.10' + testImplementation 'org.hamcrest:hamcrest:2.2' + + testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.1" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1" + + testImplementation "org.testfx:testfx-core:4.0.17" +} + +javafx { + version = "17" + modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics', 'javafx.base' ] +} + +test { + useJUnitPlatform() + + if (System.getenv("CI") == "true") { + jvmArgs = [ + "-Dtestfx.robot=glass", + "-Dtestfx.headless=true", + "-Dprism.order=sw", + "-Dprism.text=t2k", + "-Djava.awt.headless=true" + ] + } +} + +spotless { + java { + lineEndings LineEnding.UNIX + target 'src/**/*.java' + + palantirJavaFormat() + removeUnusedImports() + endWithNewline() + trimTrailingWhitespace() + } +} + +mainClassName = 'satyamconsignment.Launcher' + +application { + mainClassName = mainClassName +} + +run { + jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED'] + jvmArgs += ['--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED'] + jvmArgs += ['--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED'] + jvmArgs += ['--add-exports=javafx.base/com.sun.javafx.binding=ALL-UNNAMED'] + jvmArgs += ['--add-exports=javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED'] +} + +shadowJar { + archiveClassifier.set("") +} + +tasks.register('copyScripts', Copy) { + from('scripts') { + include 'start.sh' + include 'start.bat' + } + into "${layout.buildDirectory.get()}/libs" + doLast { + println "Copied scripts to build directory" + } +} + +tasks.named('shadowJar') { + dependsOn ( + tasks.named('copyScripts') + ) +} diff --git a/src/main/java/satyamconsignment/Launcher.java b/src/main/java/satyamconsignment/Launcher.java index 0e4e141..4c30a3e 100644 --- a/src/main/java/satyamconsignment/Launcher.java +++ b/src/main/java/satyamconsignment/Launcher.java @@ -1,45 +1,44 @@ -package satyamconsignment; - -import java.io.InputStream; -import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.image.Image; -import javafx.stage.Stage; -import satyamconsignment.common.Utils; - -public class Launcher extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage stage) { - try { - String mainFxmlPath = "/satyamconsignment/ui/Main/Main.fxml"; - URL resource = getClass().getResource(mainFxmlPath); - if (resource == null) { - throw new RuntimeException("Resource not found"); - } - Parent root = FXMLLoader.load(resource); - Scene scene = new Scene(root); - stage.setScene(scene); - stage.setMaximized(true); - stage.show(); - InputStream resourceAsStream = getClass() - .getResourceAsStream("/satyamconsignment/icons/Icon.png"); - if (resourceAsStream != null) { - stage.getIcons().add(new Image(resourceAsStream)); - } - stage.setTitle("Satyam Consignment"); - } catch (Exception ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, ex.toString(), ex); - } - } -} +package satyamconsignment; + +import java.io.InputStream; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.stage.Stage; +import satyamconsignment.common.Utils; + +public class Launcher extends Application { + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage stage) { + try { + String mainFxmlPath = "/satyamconsignment/ui/Main/Main.fxml"; + URL resource = getClass().getResource(mainFxmlPath); + if (resource == null) { + throw new RuntimeException("Resource not found"); + } + Parent root = FXMLLoader.load(resource); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.setMaximized(true); + stage.show(); + InputStream resourceAsStream = getClass().getResourceAsStream("/satyamconsignment/icons/Icon.png"); + if (resourceAsStream != null) { + stage.getIcons().add(new Image(resourceAsStream)); + } + stage.setTitle("Satyam Consignment"); + } catch (Exception ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } +} diff --git a/src/main/java/satyamconsignment/common/DatabaseHandler.java b/src/main/java/satyamconsignment/common/DatabaseHandler.java index ac8f6f9..5e9b07a 100644 --- a/src/main/java/satyamconsignment/common/DatabaseHandler.java +++ b/src/main/java/satyamconsignment/common/DatabaseHandler.java @@ -1,73 +1,70 @@ -package satyamconsignment.common; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -public final class DatabaseHandler { - - private static DatabaseHandler databaseHandler = null; - private Connection conn = null; - - private String getInitSQL() throws IOException { - return new String( - Objects.requireNonNull( - DatabaseHandler.class.getResourceAsStream("/sql/init.sql") - ).readAllBytes(), - StandardCharsets.UTF_8 - ); - } - - private void initDatabase(Connection conn) { - try { - String initSQL = getInitSQL(); - try (Statement st = conn.createStatement()) { - - for (String statement : initSQL.split(";")) { - String cleanedStatement = statement.trim(); - if (!cleanedStatement.isEmpty()) { - st.execute(cleanedStatement); - } - } - - conn.commit(); - } catch (Exception e) { - conn.rollback(); - throw e; - } finally { - conn.setAutoCommit(true); - } - } catch (Exception ex) { - System.out.println(ex.toString()); - } - - } - - private DatabaseHandler() { - try { - Class.forName("org.sqlite.JDBC"); - conn = DriverManager.getConnection("jdbc:sqlite:" + Constants.DATABASE_FILE_NAME); - initDatabase(conn); - } catch (ClassNotFoundException | SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(DatabaseHandler.class.getName()).log(Level.SEVERE, ex.toString(), ex); - } - } - - public static DatabaseHandler getInstance() { - if (databaseHandler == null) { - databaseHandler = new DatabaseHandler(); - } - return databaseHandler; - } - - public Connection getConnection() { - return conn; - } -} +package satyamconsignment.common; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +public final class DatabaseHandler { + + private static DatabaseHandler databaseHandler = null; + private Connection conn = null; + + private String getInitSQL() throws IOException { + return new String( + Objects.requireNonNull(DatabaseHandler.class.getResourceAsStream("/sql/init.sql")) + .readAllBytes(), + StandardCharsets.UTF_8); + } + + private void initDatabase(Connection conn) { + try { + String initSQL = getInitSQL(); + try (Statement st = conn.createStatement()) { + + for (String statement : initSQL.split(";")) { + String cleanedStatement = statement.trim(); + if (!cleanedStatement.isEmpty()) { + st.execute(cleanedStatement); + } + } + + conn.commit(); + } catch (Exception e) { + conn.rollback(); + throw e; + } finally { + conn.setAutoCommit(true); + } + } catch (Exception ex) { + System.out.println(ex.toString()); + } + } + + private DatabaseHandler() { + try { + Class.forName("org.sqlite.JDBC"); + conn = DriverManager.getConnection("jdbc:sqlite:" + Constants.DATABASE_FILE_NAME); + initDatabase(conn); + } catch (ClassNotFoundException | SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(DatabaseHandler.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + public static DatabaseHandler getInstance() { + if (databaseHandler == null) { + databaseHandler = new DatabaseHandler(); + } + return databaseHandler; + } + + public Connection getConnection() { + return conn; + } +} diff --git a/src/main/java/satyamconsignment/common/Utils.java b/src/main/java/satyamconsignment/common/Utils.java index 42d08f6..c9308a0 100644 --- a/src/main/java/satyamconsignment/common/Utils.java +++ b/src/main/java/satyamconsignment/common/Utils.java @@ -1,63 +1,61 @@ -package satyamconsignment.common; - -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class Utils { - - public static void showAlert(String message) { - Alert alert = new Alert(AlertType.ERROR); - alert.setContentText(message); - alert.show(); - } - - private static AlertType getAlertTypeFromCustomValue(int choice) { - switch (choice) { - case 0 : - return AlertType.ERROR; - case 1 : - return AlertType.INFORMATION; - case 2 : - return AlertType.WARNING; - case 3 : - return AlertType.CONFIRMATION; - default : - showAlert("Programming Error. Select 1->error 2->info 3->warn 4->confirm"); - } - return AlertType.NONE; - } - - public static void showAlert(String message, int choice) { - Alert alert = new Alert(getAlertTypeFromCustomValue(choice), message); - alert.show(); - } - - public static void launchPdf(String filename) { - File pdfFile = new File(filename); - - if (!pdfFile.exists()) { - showAlert("File does not exist: " + pdfFile.getAbsolutePath()); - return; - } - - if (!Desktop.isDesktopSupported()) { - showAlert("Desktop is not supported on this platform."); - return; - } - - try { - Desktop.getDesktop().open(pdfFile); - showAlert("PDF opened successfully.", 1); - } catch (IOException e) { - String msg = ("Error opening PDF: " + e.getMessage()); - Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, msg, e); - } - } - -} +package satyamconsignment.common; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; + +public class Utils { + + public static void showAlert(String message) { + Alert alert = new Alert(AlertType.ERROR); + alert.setContentText(message); + alert.show(); + } + + private static AlertType getAlertTypeFromCustomValue(int choice) { + switch (choice) { + case 0: + return AlertType.ERROR; + case 1: + return AlertType.INFORMATION; + case 2: + return AlertType.WARNING; + case 3: + return AlertType.CONFIRMATION; + default: + showAlert("Programming Error. Select 1->error 2->info 3->warn 4->confirm"); + } + return AlertType.NONE; + } + + public static void showAlert(String message, int choice) { + Alert alert = new Alert(getAlertTypeFromCustomValue(choice), message); + alert.show(); + } + + public static void launchPdf(String filename) { + File pdfFile = new File(filename); + + if (!pdfFile.exists()) { + showAlert("File does not exist: " + pdfFile.getAbsolutePath()); + return; + } + + if (!Desktop.isDesktopSupported()) { + showAlert("Desktop is not supported on this platform."); + return; + } + + try { + Desktop.getDesktop().open(pdfFile); + showAlert("PDF opened successfully.", 1); + } catch (IOException e) { + String msg = ("Error opening PDF: " + e.getMessage()); + Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, msg, e); + } + } +} diff --git a/src/main/java/satyamconsignment/common/ViewLoader.java b/src/main/java/satyamconsignment/common/ViewLoader.java index b1b59a6..dd0ac04 100644 --- a/src/main/java/satyamconsignment/common/ViewLoader.java +++ b/src/main/java/satyamconsignment/common/ViewLoader.java @@ -1,5 +1,9 @@ package satyamconsignment.common; +import java.io.IOException; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; import javafx.fxml.FXMLLoader; import javafx.scene.Group; import javafx.scene.Parent; @@ -7,16 +11,10 @@ import satyamconsignment.ui.Input.InputController; import satyamconsignment.ui.Main.MainController; -import java.io.IOException; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - public class ViewLoader { public void loadRoot(String resourcePath, Group root) { try { - Parent parent = FXMLLoader - .load(Objects.requireNonNull(getClass().getResource(resourcePath))); + Parent parent = FXMLLoader.load(Objects.requireNonNull(getClass().getResource(resourcePath))); root.getChildren().setAll(parent); } catch (IOException ex) { Utils.showAlert(ex.toString()); @@ -26,8 +24,7 @@ public void loadRoot(String resourcePath, Group root) { public void loadCenter(String resourcePath, BorderPane center) { try { - Parent parent = FXMLLoader - .load(Objects.requireNonNull(getClass().getResource(resourcePath))); + Parent parent = FXMLLoader.load(Objects.requireNonNull(getClass().getResource(resourcePath))); center.setCenter(parent); } catch (IOException ex) { Utils.showAlert(ex.toString()); diff --git a/src/main/java/satyamconsignment/model/BillRecord.java b/src/main/java/satyamconsignment/model/BillRecord.java index 1dac746..8ce5d29 100644 --- a/src/main/java/satyamconsignment/model/BillRecord.java +++ b/src/main/java/satyamconsignment/model/BillRecord.java @@ -1,18 +1,18 @@ -package satyamconsignment.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor -@Getter -@Setter -public class BillRecord { - private String supplierName; - private String buyerName; - private String billNo; - private String billDate; - private String transport; - private String lrDate; - private String billAmount; -} +package satyamconsignment.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +public class BillRecord { + private String supplierName; + private String buyerName; + private String billNo; + private String billDate; + private String transport; + private String lrDate; + private String billAmount; +} diff --git a/src/main/java/satyamconsignment/model/CollectionItem.java b/src/main/java/satyamconsignment/model/CollectionItem.java index c61ed23..fa76d44 100644 --- a/src/main/java/satyamconsignment/model/CollectionItem.java +++ b/src/main/java/satyamconsignment/model/CollectionItem.java @@ -1,27 +1,27 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package satyamconsignment.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor -@Getter -@Setter -@Builder -public class CollectionItem { - private String billNo; - private String billDate; - private String billAmount; - private String supplierName; - private String due; - private String amountCollected; - private String bank; - private String ddNo; - private String ddDate; -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package satyamconsignment.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class CollectionItem { + private String billNo; + private String billDate; + private String billAmount; + private String supplierName; + private String due; + private String amountCollected; + private String bank; + private String ddNo; + private String ddDate; +} diff --git a/src/main/java/satyamconsignment/model/LR.java b/src/main/java/satyamconsignment/model/LR.java index 52ed555..9d3f8c7 100644 --- a/src/main/java/satyamconsignment/model/LR.java +++ b/src/main/java/satyamconsignment/model/LR.java @@ -1,14 +1,14 @@ -package satyamconsignment.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor -@Getter -@Setter -public class LR { - private String billNo; - private String lrNo; - private String pm; -} +package satyamconsignment.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +public class LR { + private String billNo; + private String lrNo; + private String pm; +} diff --git a/src/main/java/satyamconsignment/model/PaymentItem.java b/src/main/java/satyamconsignment/model/PaymentItem.java index e4aefc4..fab42a2 100644 --- a/src/main/java/satyamconsignment/model/PaymentItem.java +++ b/src/main/java/satyamconsignment/model/PaymentItem.java @@ -1,22 +1,22 @@ -package satyamconsignment.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor -@Getter -@Setter -@Builder -public class PaymentItem { - private String billNo; - private String billAmount; - private String billDate; - private String buyerName; - private String due; - private String amountPaid; - private String bank; - private String ddNo; - private String ddDate; -} +package satyamconsignment.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class PaymentItem { + private String billNo; + private String billAmount; + private String billDate; + private String buyerName; + private String due; + private String amountPaid; + private String bank; + private String ddNo; + private String ddDate; +} diff --git a/src/main/java/satyamconsignment/ui/Input/BillEntry/AddBill/AddBill.java b/src/main/java/satyamconsignment/ui/Input/BillEntry/AddBill/AddBill.java index 9f67ce5..3550a05 100644 --- a/src/main/java/satyamconsignment/ui/Input/BillEntry/AddBill/AddBill.java +++ b/src/main/java/satyamconsignment/ui/Input/BillEntry/AddBill/AddBill.java @@ -1,221 +1,233 @@ -package satyamconsignment.ui.Input.BillEntry.AddBill; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import org.controlsfx.control.textfield.TextFields; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.ui.Input.BillEntry.BillEntryController; -import satyamconsignment.model.LR; - -public class AddBill implements Initializable { - - @FXML - private TextField supplier_field; - @FXML - private TextField buyer_name_field; - @FXML - private TextField bill_no_field; - @FXML - private TextField transport_field; - @FXML - private DatePicker date_field; - @FXML - private DatePicker lr_date; - @FXML - private TextField bill_amount_field; - @FXML - private TextField pm_field; - @FXML - private TextField lr_field; - @FXML - private Button save_btn; - @FXML - private Button clear_btn; - @FXML - private Button add_btn; - @FXML - private TableView lrTable; - @FXML - private TableColumn lr_no_col; - @FXML - private TableColumn pm_col; - @FXML - private Button replace_btn; - @FXML - private Button delete_btn; - - final ObservableList lrList = FXCollections.observableArrayList(); - - @Override - public void initialize(URL url, ResourceBundle rb) { - try { - ArrayList supplierList = new ArrayList<>(); - ArrayList buyerList = new ArrayList<>(); - ArrayList transportList = new ArrayList<>(); - Connection connection = DatabaseHandler.getInstance().getConnection(); - ResultSet supplierResultSet = connection - .prepareStatement( - "select * from Supplier_Master_Table order by name collate nocase") - .executeQuery(); - ResultSet buyerResultSet = connection - .prepareStatement( - "select * from Buyer_Master_Table order by name collate nocase") - .executeQuery(); - ResultSet transportResultSet = connection - .prepareStatement( - "select * from Transport_Master_Table order by name collate nocase") - .executeQuery(); - while (supplierResultSet.next()) { - supplierList.add(supplierResultSet.getString("name")); - } - while (buyerResultSet.next()) { - buyerList.add(buyerResultSet.getString("name")); - } - while (transportResultSet.next()) { - transportList.add(transportResultSet.getString("name")); - } - - TextFields.bindAutoCompletion(supplier_field, supplierList); - TextFields.bindAutoCompletion(buyer_name_field, buyerList); - TextFields.bindAutoCompletion(transport_field, transportList); - - lr_no_col.setCellValueFactory(new PropertyValueFactory<>("lrNo")); - pm_col.setCellValueFactory(new PropertyValueFactory<>("pm")); - - } catch (Exception ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); - } - } - - @FXML - private void addToList(ActionEvent event) { - if (bill_no_field.getText().isEmpty() || lr_field.getText().isEmpty() - || pm_field.getText().isEmpty()) { - Utils.showAlert( - "Please ensure that the Bill No., LR No. and PM fields are filled up properly.", - 2); - return; - } - lrList.add(new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText())); - lrTable.setItems(lrList); - lr_field.clear(); - pm_field.clear(); - - } - - @FXML - private void save(ActionEvent event) { - if (supplier_field.getText().isEmpty() || buyer_name_field.getText().isEmpty() - || bill_no_field.getText().isEmpty() || date_field.getValue().toString().isEmpty() - || transport_field.getText().isEmpty() || lr_date.getValue().toString().isEmpty() - || bill_amount_field.getText().isEmpty() || lrList.isEmpty()) { - Utils.showAlert("Please ensure to fill up all the fields"); - return; - } - /* Code for saving data into Bill_Entry_Table */ - Connection connection = DatabaseHandler.getInstance().getConnection(); - try { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); - String sql = "INSERT INTO `Bill_Entry_Table`(`Supplier Name`,`Buyer Name`,`Bill No.`,`Bill Date`,`Transport`,`LR Date`,`Bill Amount`,`Collection Due`,`Due`) VALUES (?,?,?,?,?,?,?,?,?);"; - - connection.setAutoCommit(false); - - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, supplier_field.getText()); - preparedStatement.setString(2, buyer_name_field.getText()); - preparedStatement.setString(3, bill_no_field.getText()); - preparedStatement.setString(4, formatter.format(date_field.getValue())); - preparedStatement.setString(5, transport_field.getText()); - preparedStatement.setString(6, formatter.format(lr_date.getValue())); - preparedStatement.setString(7, bill_amount_field.getText()); - preparedStatement.setString(8, bill_amount_field.getText()); - preparedStatement.setString(9, bill_amount_field.getText()); - preparedStatement.execute(); - - /* Code for Entering Data into LR_Table */ - for (LR lr : lrList) { - sql = "INSERT INTO `LR_Table`(`Bill No.`,`LR No.`,`PM`) VALUES (?,?,?)"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, bill_no_field.getText()); - preparedStatement.setString(2, lr.getLrNo()); - preparedStatement.setString(3, lr.getPm()); - preparedStatement.execute(); - } - clearAllFields(); - connection.commit(); - Utils.showAlert("Saved Successfully", 1); - } catch (Exception ex) { - try { - connection.rollback(); - } catch (Exception ex1) { - Utils.showAlert(ex1.toString()); - Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, - ex1.toString(), ex1); - } - Utils.showAlert(ex.toString()); - Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); - } - - } - - @FXML - private void clearAllFields() { - supplier_field.clear(); - buyer_name_field.clear(); - bill_no_field.clear(); - transport_field.clear(); - date_field.setValue(null); - lr_date.setValue(null); - bill_amount_field.clear(); - pm_field.clear(); - lr_field.clear(); - lrList.clear(); - } - - @FXML - private void replaceInList(ActionEvent event) { - if (lrTable.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the LR Table", 2); - return; - } - if (bill_no_field.getText().isEmpty() || lr_field.getText().isEmpty() - || pm_field.getText().isEmpty()) { - Utils.showAlert( - "Please ensure that the Bill No., LR No. and PM fields are filled up properly.", - 2); - return; - } - lrList.set(lrTable.getSelectionModel().getSelectedIndex(), - new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText())); - lr_field.clear(); - pm_field.clear(); - } - - @FXML - private void deleteFromList(ActionEvent event) { - if (lrTable.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the LR Table", 2); - return; - } - lrList.remove(lrTable.getSelectionModel().getSelectedIndex()); - } -} +package satyamconsignment.ui.Input.BillEntry.AddBill; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import org.controlsfx.control.textfield.TextFields; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.LR; +import satyamconsignment.ui.Input.BillEntry.BillEntryController; + +public class AddBill implements Initializable { + + @FXML + private TextField supplier_field; + + @FXML + private TextField buyer_name_field; + + @FXML + private TextField bill_no_field; + + @FXML + private TextField transport_field; + + @FXML + private DatePicker date_field; + + @FXML + private DatePicker lr_date; + + @FXML + private TextField bill_amount_field; + + @FXML + private TextField pm_field; + + @FXML + private TextField lr_field; + + @FXML + private Button save_btn; + + @FXML + private Button clear_btn; + + @FXML + private Button add_btn; + + @FXML + private TableView lrTable; + + @FXML + private TableColumn lr_no_col; + + @FXML + private TableColumn pm_col; + + @FXML + private Button replace_btn; + + @FXML + private Button delete_btn; + + final ObservableList lrList = FXCollections.observableArrayList(); + + @Override + public void initialize(URL url, ResourceBundle rb) { + try { + ArrayList supplierList = new ArrayList<>(); + ArrayList buyerList = new ArrayList<>(); + ArrayList transportList = new ArrayList<>(); + Connection connection = DatabaseHandler.getInstance().getConnection(); + ResultSet supplierResultSet = connection + .prepareStatement("select * from Supplier_Master_Table order by name collate nocase") + .executeQuery(); + ResultSet buyerResultSet = connection + .prepareStatement("select * from Buyer_Master_Table order by name collate nocase") + .executeQuery(); + ResultSet transportResultSet = connection + .prepareStatement("select * from Transport_Master_Table order by name collate nocase") + .executeQuery(); + while (supplierResultSet.next()) { + supplierList.add(supplierResultSet.getString("name")); + } + while (buyerResultSet.next()) { + buyerList.add(buyerResultSet.getString("name")); + } + while (transportResultSet.next()) { + transportList.add(transportResultSet.getString("name")); + } + + TextFields.bindAutoCompletion(supplier_field, supplierList); + TextFields.bindAutoCompletion(buyer_name_field, buyerList); + TextFields.bindAutoCompletion(transport_field, transportList); + + lr_no_col.setCellValueFactory(new PropertyValueFactory<>("lrNo")); + pm_col.setCellValueFactory(new PropertyValueFactory<>("pm")); + + } catch (Exception ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void addToList(ActionEvent event) { + if (bill_no_field.getText().isEmpty() + || lr_field.getText().isEmpty() + || pm_field.getText().isEmpty()) { + Utils.showAlert("Please ensure that the Bill No., LR No. and PM fields are filled up properly.", 2); + return; + } + lrList.add(new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText())); + lrTable.setItems(lrList); + lr_field.clear(); + pm_field.clear(); + } + + @FXML + private void save(ActionEvent event) { + if (supplier_field.getText().isEmpty() + || buyer_name_field.getText().isEmpty() + || bill_no_field.getText().isEmpty() + || date_field.getValue().toString().isEmpty() + || transport_field.getText().isEmpty() + || lr_date.getValue().toString().isEmpty() + || bill_amount_field.getText().isEmpty() + || lrList.isEmpty()) { + Utils.showAlert("Please ensure to fill up all the fields"); + return; + } + /* Code for saving data into Bill_Entry_Table */ + Connection connection = DatabaseHandler.getInstance().getConnection(); + try { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + String sql = + "INSERT INTO `Bill_Entry_Table`(`Supplier Name`,`Buyer Name`,`Bill No.`,`Bill Date`,`Transport`,`LR Date`,`Bill Amount`,`Collection Due`,`Due`) VALUES (?,?,?,?,?,?,?,?,?);"; + + connection.setAutoCommit(false); + + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, supplier_field.getText()); + preparedStatement.setString(2, buyer_name_field.getText()); + preparedStatement.setString(3, bill_no_field.getText()); + preparedStatement.setString(4, formatter.format(date_field.getValue())); + preparedStatement.setString(5, transport_field.getText()); + preparedStatement.setString(6, formatter.format(lr_date.getValue())); + preparedStatement.setString(7, bill_amount_field.getText()); + preparedStatement.setString(8, bill_amount_field.getText()); + preparedStatement.setString(9, bill_amount_field.getText()); + preparedStatement.execute(); + + /* Code for Entering Data into LR_Table */ + for (LR lr : lrList) { + sql = "INSERT INTO `LR_Table`(`Bill No.`,`LR No.`,`PM`) VALUES (?,?,?)"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, bill_no_field.getText()); + preparedStatement.setString(2, lr.getLrNo()); + preparedStatement.setString(3, lr.getPm()); + preparedStatement.execute(); + } + clearAllFields(); + connection.commit(); + Utils.showAlert("Saved Successfully", 1); + } catch (Exception ex) { + try { + connection.rollback(); + } catch (Exception ex1) { + Utils.showAlert(ex1.toString()); + Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex1.toString(), ex1); + } + Utils.showAlert(ex.toString()); + Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void clearAllFields() { + supplier_field.clear(); + buyer_name_field.clear(); + bill_no_field.clear(); + transport_field.clear(); + date_field.setValue(null); + lr_date.setValue(null); + bill_amount_field.clear(); + pm_field.clear(); + lr_field.clear(); + lrList.clear(); + } + + @FXML + private void replaceInList(ActionEvent event) { + if (lrTable.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the LR Table", 2); + return; + } + if (bill_no_field.getText().isEmpty() + || lr_field.getText().isEmpty() + || pm_field.getText().isEmpty()) { + Utils.showAlert("Please ensure that the Bill No., LR No. and PM fields are filled up properly.", 2); + return; + } + lrList.set( + lrTable.getSelectionModel().getSelectedIndex(), + new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText())); + lr_field.clear(); + pm_field.clear(); + } + + @FXML + private void deleteFromList(ActionEvent event) { + if (lrTable.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the LR Table", 2); + return; + } + lrList.remove(lrTable.getSelectionModel().getSelectedIndex()); + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/BillEntry/BillEntryController.java b/src/main/java/satyamconsignment/ui/Input/BillEntry/BillEntryController.java index d5b886c..7b31eac 100644 --- a/src/main/java/satyamconsignment/ui/Input/BillEntry/BillEntryController.java +++ b/src/main/java/satyamconsignment/ui/Input/BillEntry/BillEntryController.java @@ -1,12 +1,11 @@ -package satyamconsignment.ui.Input.BillEntry; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.fxml.Initializable; - -public class BillEntryController implements Initializable { - - @Override - public void initialize(URL location, ResourceBundle resources) { - } -} +package satyamconsignment.ui.Input.BillEntry; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.fxml.Initializable; + +public class BillEntryController implements Initializable { + + @Override + public void initialize(URL location, ResourceBundle resources) {} +} diff --git a/src/main/java/satyamconsignment/ui/Input/BillEntry/ViewAndDeleteBill/ViewAndDeleteBill.java b/src/main/java/satyamconsignment/ui/Input/BillEntry/ViewAndDeleteBill/ViewAndDeleteBill.java index ee7c2c4..9cb1649 100644 --- a/src/main/java/satyamconsignment/ui/Input/BillEntry/ViewAndDeleteBill/ViewAndDeleteBill.java +++ b/src/main/java/satyamconsignment/ui/Input/BillEntry/ViewAndDeleteBill/ViewAndDeleteBill.java @@ -1,166 +1,180 @@ -package satyamconsignment.ui.Input.BillEntry.ViewAndDeleteBill; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.model.LR; - -public class ViewAndDeleteBill implements Initializable { - - private static final Logger logger = Logger.getLogger(ViewAndDeleteBill.class.getName()); - - @FXML - private TextField supplier_field; - @FXML - private TableView lr_table; - @FXML - private TableColumn lr_no_col; - @FXML - private TableColumn pm_col; - @FXML - private TextField buyer_name_field; - @FXML - private TextField bill_date_field; - @FXML - private TextField transport_field; - @FXML - private TextField bill_amount_field; - @FXML - private TextField lr_date_field; - @FXML - private Button get_details_btn; - @FXML - private Button delete_entry_btn; - @FXML - private TextField bill_no_field; - - @Override - public void initialize(URL url, ResourceBundle rb) { - lr_no_col.setCellValueFactory(new PropertyValueFactory<>("lrNo")); - pm_col.setCellValueFactory(new PropertyValueFactory<>("pm")); - } - - @FXML - private void getDetails(ActionEvent event) { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "select * from `Bill_Entry_Table` where `Bill No.`=? collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, bill_no_field.getText()); - ResultSet billResultSet = preparedStatement.executeQuery(); - String sql2 = "select * from `LR_Table` where `Bill No.`=? collate nocase"; - preparedStatement = connection.prepareStatement(sql2); - preparedStatement.setString(1, bill_no_field.getText()); - ResultSet lrPmResultSet = preparedStatement.executeQuery(); - - if (billResultSet.isClosed()) { - Utils.showAlert("Record not found. Please try again later.", 2); - return; - } - - supplier_field.setText(billResultSet.getString("Supplier Name")); - buyer_name_field.setText(billResultSet.getString("Buyer Name")); - bill_date_field.setText(billResultSet.getString("Bill Date")); - transport_field.setText(billResultSet.getString("Transport")); - lr_date_field.setText(billResultSet.getString("LR Date")); - bill_amount_field.setText(billResultSet.getString("Bill Amount")); - - List lrpmList = new ArrayList<>(); - while (lrPmResultSet.next()) { - lrpmList.add(new LR(lrPmResultSet.getString("Bill No."), - lrPmResultSet.getString("LR No."), lrPmResultSet.getString("PM"))); - } - lr_table.setItems(FXCollections.observableArrayList(lrpmList)); - delete_entry_btn.setDisable(false); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, null, ex); - } - } - - @FXML - private void deleteEntry(ActionEvent event) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION, - "Are you sure that you want delete " + bill_no_field.getText() + " ?", - ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - alert.showAndWait(); - - if (alert.getResult() != ButtonType.YES) { - return; - } - - Connection connection = DatabaseHandler.getInstance().getConnection(); - - try { - connection.setAutoCommit(false); - String sql = "DELETE FROM `Bill_Entry_Table` where `Bill No.`=? collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, bill_no_field.getText()); - preparedStatement.execute(); - - String sql2 = "DELETE FROM `LR_Table` where `Bill No.`=? collate nocase"; - preparedStatement = connection.prepareStatement(sql2); - preparedStatement.setString(1, bill_no_field.getText()); - preparedStatement.execute(); - supplier_field.setText(""); - buyer_name_field.setText(""); - bill_date_field.setText(""); - transport_field.setText(""); - lr_date_field.setText(""); - bill_amount_field.setText(""); - lr_table.setItems(FXCollections.observableArrayList()); - connection.commit(); - Utils.showAlert( - bill_no_field.getText().toUpperCase() + " Entry was successfully deleted.", 1); - } catch (SQLException ex) { - try { - connection.rollback(); - } catch (SQLException ex1) { - Utils.showAlert(ex1.toString()); - logger.log(Level.SEVERE, ex1.toString(), ex1); - } - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } - - @FXML - public void updateBill(ActionEvent actionEvent) { - Connection connection = DatabaseHandler.getInstance().getConnection(); - try { - connection.setAutoCommit(false); - String sql = "UPDATE `Bill_Entry_Table` SET `Supplier Name`=?,`Buyer Name`=?,`Bill Date`=?," - + "`Transport`=?,`LR Date`=?,`Bill Amount`=?,`Collection Due`=?,`Due`=? WHERE `Bill No.`=?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, supplier_field.getText()); - preparedStatement.setString(2, buyer_name_field.getText()); - preparedStatement.setString(3, bill_date_field.getText()); - preparedStatement.setString(4, transport_field.getText()); - preparedStatement.setString(5, lr_date_field.getText()); - preparedStatement.setString(6, bill_amount_field.getText()); - preparedStatement.setString(7, bill_amount_field.getText()); - preparedStatement.setString(8, bill_amount_field.getText()); - preparedStatement.setString(9, bill_no_field.getText()); - preparedStatement.execute(); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } -} +package satyamconsignment.ui.Input.BillEntry.ViewAndDeleteBill; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.LR; + +public class ViewAndDeleteBill implements Initializable { + + private static final Logger logger = Logger.getLogger(ViewAndDeleteBill.class.getName()); + + @FXML + private TextField supplier_field; + + @FXML + private TableView lr_table; + + @FXML + private TableColumn lr_no_col; + + @FXML + private TableColumn pm_col; + + @FXML + private TextField buyer_name_field; + + @FXML + private TextField bill_date_field; + + @FXML + private TextField transport_field; + + @FXML + private TextField bill_amount_field; + + @FXML + private TextField lr_date_field; + + @FXML + private Button get_details_btn; + + @FXML + private Button delete_entry_btn; + + @FXML + private TextField bill_no_field; + + @Override + public void initialize(URL url, ResourceBundle rb) { + lr_no_col.setCellValueFactory(new PropertyValueFactory<>("lrNo")); + pm_col.setCellValueFactory(new PropertyValueFactory<>("pm")); + } + + @FXML + private void getDetails(ActionEvent event) { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "select * from `Bill_Entry_Table` where `Bill No.`=? collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, bill_no_field.getText()); + ResultSet billResultSet = preparedStatement.executeQuery(); + String sql2 = "select * from `LR_Table` where `Bill No.`=? collate nocase"; + preparedStatement = connection.prepareStatement(sql2); + preparedStatement.setString(1, bill_no_field.getText()); + ResultSet lrPmResultSet = preparedStatement.executeQuery(); + + if (billResultSet.isClosed()) { + Utils.showAlert("Record not found. Please try again later.", 2); + return; + } + + supplier_field.setText(billResultSet.getString("Supplier Name")); + buyer_name_field.setText(billResultSet.getString("Buyer Name")); + bill_date_field.setText(billResultSet.getString("Bill Date")); + transport_field.setText(billResultSet.getString("Transport")); + lr_date_field.setText(billResultSet.getString("LR Date")); + bill_amount_field.setText(billResultSet.getString("Bill Amount")); + + List lrpmList = new ArrayList<>(); + while (lrPmResultSet.next()) { + lrpmList.add(new LR( + lrPmResultSet.getString("Bill No."), + lrPmResultSet.getString("LR No."), + lrPmResultSet.getString("PM"))); + } + lr_table.setItems(FXCollections.observableArrayList(lrpmList)); + delete_entry_btn.setDisable(false); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, null, ex); + } + } + + @FXML + private void deleteEntry(ActionEvent event) { + Alert alert = new Alert( + Alert.AlertType.CONFIRMATION, + "Are you sure that you want delete " + bill_no_field.getText() + " ?", + ButtonType.YES, + ButtonType.NO, + ButtonType.CANCEL); + alert.showAndWait(); + + if (alert.getResult() != ButtonType.YES) { + return; + } + + Connection connection = DatabaseHandler.getInstance().getConnection(); + + try { + connection.setAutoCommit(false); + String sql = "DELETE FROM `Bill_Entry_Table` where `Bill No.`=? collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, bill_no_field.getText()); + preparedStatement.execute(); + + String sql2 = "DELETE FROM `LR_Table` where `Bill No.`=? collate nocase"; + preparedStatement = connection.prepareStatement(sql2); + preparedStatement.setString(1, bill_no_field.getText()); + preparedStatement.execute(); + supplier_field.setText(""); + buyer_name_field.setText(""); + bill_date_field.setText(""); + transport_field.setText(""); + lr_date_field.setText(""); + bill_amount_field.setText(""); + lr_table.setItems(FXCollections.observableArrayList()); + connection.commit(); + Utils.showAlert(bill_no_field.getText().toUpperCase() + " Entry was successfully deleted.", 1); + } catch (SQLException ex) { + try { + connection.rollback(); + } catch (SQLException ex1) { + Utils.showAlert(ex1.toString()); + logger.log(Level.SEVERE, ex1.toString(), ex1); + } + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + public void updateBill(ActionEvent actionEvent) { + Connection connection = DatabaseHandler.getInstance().getConnection(); + try { + connection.setAutoCommit(false); + String sql = "UPDATE `Bill_Entry_Table` SET `Supplier Name`=?,`Buyer Name`=?,`Bill Date`=?," + + "`Transport`=?,`LR Date`=?,`Bill Amount`=?,`Collection Due`=?,`Due`=? WHERE `Bill No.`=?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, supplier_field.getText()); + preparedStatement.setString(2, buyer_name_field.getText()); + preparedStatement.setString(3, bill_date_field.getText()); + preparedStatement.setString(4, transport_field.getText()); + preparedStatement.setString(5, lr_date_field.getText()); + preparedStatement.setString(6, bill_amount_field.getText()); + preparedStatement.setString(7, bill_amount_field.getText()); + preparedStatement.setString(8, bill_amount_field.getText()); + preparedStatement.setString(9, bill_no_field.getText()); + preparedStatement.execute(); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/AddCollection/AddCollection.java b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/AddCollection/AddCollection.java index 47f53c5..97c6db6 100644 --- a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/AddCollection/AddCollection.java +++ b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/AddCollection/AddCollection.java @@ -1,382 +1,422 @@ -package satyamconsignment.ui.Input.CollectionEntry.AddCollection; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.model.CollectionItem; - -public class AddCollection implements Initializable { - private List collectionItemList; - private List buyerNameComboList; - private List billNoComboList; - private int previouslyDue; - - private static final Logger logger = Logger.getLogger(AddCollection.class.getName()); - - @FXML - private TextField dd_no_field; - @FXML - private DatePicker dd_date_field; - @FXML - private TextField voucher_no_field; - @FXML - private DatePicker voucher_date_field; - @FXML - private TableView collection_tableview; - @FXML - private TableColumn bill_no_col; - @FXML - private TableColumn bill_amt_col; - @FXML - private TableColumn supplier_col; - @FXML - private TableColumn amount_collection_col; - @FXML - private TableColumn bank_col; - @FXML - private TableColumn dd_no_col; - @FXML - private TableColumn dd_date_col; - @FXML - private TextField bill_date; - @FXML - private TextField bill_amount; - @FXML - private ComboBox buyer_name; - @FXML - private TextField supplier_name; - @FXML - private ComboBox bill_no_combo; - @FXML - private TextField bank_field; - - @FXML - private TextField total_amount_field; - - @FXML - private TextField amount_collected_field; - @FXML - private TextField collection_due_field; - @FXML - private Label last_voucher_field; - - @Override - public void initialize(URL url, ResourceBundle rb) { - collectionItemList = new ArrayList<>(); - buyerNameComboList = new ArrayList<>(); - billNoComboList = new ArrayList<>(); - bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); - bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); - supplier_col.setCellValueFactory(new PropertyValueFactory<>("supplierName")); - amount_collection_col.setCellValueFactory(new PropertyValueFactory<>("amountCollected")); - dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); - bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); - dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); - refreshCollectionTableView(); - fillBuyerNameCombo(); - updateLastVoucher(); - } - - private void refreshCollectionTableView() { - collection_tableview.setItems(FXCollections.observableArrayList(collectionItemList)); - } - - private void fillBuyerNameCombo() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "select Name from `Buyer_Master_Table` order by name collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - ResultSet buyerMasterResultSet = preparedStatement.executeQuery(); - - buyerNameComboList.clear(); - while (buyerMasterResultSet.next()) { - buyerNameComboList.add(buyerMasterResultSet.getString("Name")); - } - - buyer_name.setItems(FXCollections.observableArrayList(buyerNameComboList)); - - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } - - @FXML - private void fillBillNoCombo() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - - String getCollectionAmountsForEveryoneSql = "select `Bill No.`, sum(`Amount Collected`) as `Amount Collected` " - + "from `Collection_Entry_Extended_Table` group by `Bill No.`"; - Map collectionAmountMap = new HashMap<>(); - PreparedStatement preparedStatement = connection - .prepareStatement(getCollectionAmountsForEveryoneSql); - ResultSet collectionAmountsResultSet = preparedStatement.executeQuery(); - while (collectionAmountsResultSet.next()) { - String amountCollectedStr = collectionAmountsResultSet - .getString("Amount Collected"); - double amountCollected = 0; - try { - amountCollected = Double.parseDouble(amountCollectedStr); - } catch (NumberFormatException ex) { - logger.log(Level.SEVERE, ex.toString(), ex); - Utils.showAlert(ex.toString()); - } - collectionAmountMap.put(collectionAmountsResultSet.getString("Bill No."), - amountCollected); - } - - String getBillAmountsForBuyerSql = "select `Bill No.`, `Bill Amount` from `Bill_Entry_Table` " - + "where `Buyer Name`=? order by `Bill No.` collate nocase"; - - preparedStatement = connection.prepareStatement(getBillAmountsForBuyerSql); - preparedStatement.setString(1, buyer_name.getValue()); - ResultSet billNoResultSet = preparedStatement.executeQuery(); - - billNoComboList.clear(); - - while (billNoResultSet.next()) { - String billNo = billNoResultSet.getString("Bill No."); - String billAmountStr = billNoResultSet.getString("Bill Amount"); - double billAmount = 1.0; - try { - billAmount = Double.parseDouble(billAmountStr); - } catch (NumberFormatException ex) { - logger.log(Level.SEVERE, ex.toString(), ex); - Utils.showAlert(ex.toString()); - } - if (collectionAmountMap.containsKey(billNo)) { - if (billAmount - collectionAmountMap.get(billNo) > 0) { - billNoComboList.add(billNo); - } - } else { - billNoComboList.add(billNo); - } - } - - bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList)); - - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } - - @FXML - private void fetchData() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "Select * from Bill_Entry_Table where `Bill No.`=?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, bill_no_combo.getValue()); - ResultSet billResultSet = preparedStatement.executeQuery(); - String supplierName = billResultSet.getString("Supplier Name"); - String billDate = billResultSet.getString("Bill Date"); - String billAmount = billResultSet.getString("Bill Amount"); - previouslyDue = Integer.parseInt(billResultSet.getString("Collection Due")); - supplier_name.setText(supplierName); - bill_date.setText(billDate); - bill_amount.setText(billAmount); - updateCollectionDue(); - // buyer_name.setDisable(true); - billResultSet.close(); - - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } - - @FXML - private void addCollection(ActionEvent ignoredEvent) { - if (bill_no_combo.getValue().isEmpty() || bill_amount.getText().isEmpty() - || buyer_name.getValue().isEmpty() || supplier_name.getText().isEmpty() - || bank_field.getText().isEmpty() || collection_due_field.getText().isEmpty() - || amount_collected_field.getText().isEmpty() || dd_no_field.getText().isEmpty() - || dd_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Please check whether the fields are properly filled or not.", 2); - return; - } - - DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern(Constants.DATE_TIME_FORMAT); - - collectionItemList.add(new CollectionItem(bill_no_combo.getValue(), bill_date.getText(), - bill_amount.getText(), supplier_name.getText(), collection_due_field.getText(), - amount_collected_field.getText(), bank_field.getText(), dd_no_field.getText(), - dateTimeFormatter.format(dd_date_field.getValue()))); - - refreshCollectionTableView(); - updateTotalAmount(); - clearRepeatingFields(); - } - - @FXML - private void updateCollectionDue() { - collection_due_field.setText(Integer - .toString(previouslyDue - Integer.parseInt(amount_collected_field.getText()))); - } - - private void updateTotalAmount() { - int totalAmount = 0; - for (CollectionItem collectionItem : collectionItemList) { - totalAmount += Integer.parseInt(collectionItem.getAmountCollected()); - } - total_amount_field.setText(Integer.toString(totalAmount)); - } - - private void clearRepeatingFields() { - bill_date.setText(""); - supplier_name.setText(""); - bill_amount.setText(""); - collection_due_field.setText("0"); - amount_collected_field.setText("0"); - bank_field.setText(""); - dd_no_field.setText(""); - - dd_date_field.setValue(null); - } - - @FXML - private void replaceCollection(ActionEvent ignoredEvent) { - if (collection_tableview.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the Collection Table", 2); - return; - } - if (bill_no_combo.getValue().isEmpty() || bill_amount.getText().isEmpty() - || buyer_name.getValue().isEmpty() || supplier_name.getText().isEmpty() - || bank_field.getText().isEmpty() || collection_due_field.getText().isEmpty() - || amount_collected_field.getText().isEmpty() || dd_no_field.getText().isEmpty() - || dd_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Please check whether the fields are properly filled or not.", 2); - return; - } - collectionItemList.set(collection_tableview.getSelectionModel().getSelectedIndex(), - CollectionItem.builder().billNo(bill_no_combo.getValue()) - .billDate(bill_date.getText()).billAmount(bill_amount.getText()) - .supplierName(supplier_name.getText()).due(collection_due_field.getText()) - .amountCollected(amount_collected_field.getText()) - .bank(bank_field.getText()).ddNo(dd_no_field.getText()) - .ddDate(dd_date_field.getValue().toString()).build()); - refreshCollectionTableView(); - updateTotalAmount(); - } - - @FXML - private void deleteCollection(ActionEvent ignoredEvent) { - if (collection_tableview.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the LR Table", 2); - return; - } - collectionItemList.remove(collection_tableview.getSelectionModel().getSelectedIndex()); - refreshCollectionTableView(); - updateTotalAmount(); - } - - @FXML - private void clearAllFields() { - clearRepeatingFields(); - voucher_no_field.setText(""); - voucher_date_field.setValue(null); - buyer_name.setDisable(false); - billNoComboList.clear(); - } - - @FXML - private void saveData(ActionEvent ignoredEvent) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION, - "Are you sure that you want save " + voucher_no_field.getText() + " ?", - ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - alert.showAndWait(); - - if (alert.getResult() != ButtonType.YES) { - return; - } - if (voucher_no_field.getText().isEmpty() || voucher_date_field.getValue() == null - || voucher_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Check whether the Voucher No. and the Voucher Date is properly filled", - 2); - return; - } - Connection connection = DatabaseHandler.getInstance().getConnection(); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern(Constants.DATE_TIME_FORMAT); - try { - connection.setAutoCommit(false); - String sql = "INSERT INTO `Collection_Entry_Table`(`Voucher No.`,`Voucher Date`,`Buyer Name`,`Total Amount`) VALUES (?,?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.setString(2, dateTimeFormatter.format(voucher_date_field.getValue())); - preparedStatement.setString(3, buyer_name.getValue()); - preparedStatement.setString(4, total_amount_field.getText()); - preparedStatement.execute(); - - for (CollectionItem collectionItem : collectionItemList) { - sql = "INSERT INTO `Collection_Entry_Extended_Table`(`Voucher No.`,`Supplier Name`,`Bill No.`,`Bill Date`,`Bill Amount`,`Collection Due`,`Amount Collected`,`Bank`,`DD No.`,`DD Date`) VALUES (?,?,?,?,?,?,?,?,?,?);"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.setString(2, collectionItem.getSupplierName()); - preparedStatement.setString(3, collectionItem.getBillNo()); - preparedStatement.setString(4, collectionItem.getBillDate()); - preparedStatement.setString(5, collectionItem.getBillAmount()); - preparedStatement.setString(6, collectionItem.getDue()); - preparedStatement.setString(7, collectionItem.getAmountCollected()); - preparedStatement.setString(8, collectionItem.getBank()); - preparedStatement.setString(9, collectionItem.getDdNo()); - preparedStatement.setString(10, collectionItem.getDdDate()); - - preparedStatement.execute(); - - // Update Bill Entry Table - sql = "UPDATE `Bill_Entry_Table` SET `Collection Due`=? WHERE `BILL NO.`=?"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, collectionItem.getDue()); - preparedStatement.setString(2, collectionItem.getBillNo()); - preparedStatement.execute(); - } - connection.commit(); - Utils.showAlert("Saved Successfully", 1); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - try { - connection.rollback(); - } catch (SQLException ex1) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex1.toString(), ex1); - } - } - clearAllFields(); - collectionItemList.clear(); - refreshCollectionTableView(); - } - - private void updateLastVoucher() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "SELECT MAX(`Voucher No.`) from `COLLECTION_ENTRY_TABLE`;"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - ResultSet resultSet = preparedStatement.executeQuery(); - String answer = resultSet.getString("Max(`Voucher No.`)"); - last_voucher_field.setText("Last Voucher No. : " + answer); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString(), ex); - } - } -} +package satyamconsignment.ui.Input.CollectionEntry.AddCollection; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.CollectionItem; + +public class AddCollection implements Initializable { + private List collectionItemList; + private List buyerNameComboList; + private List billNoComboList; + private int previouslyDue; + + private static final Logger logger = Logger.getLogger(AddCollection.class.getName()); + + @FXML + private TextField dd_no_field; + + @FXML + private DatePicker dd_date_field; + + @FXML + private TextField voucher_no_field; + + @FXML + private DatePicker voucher_date_field; + + @FXML + private TableView collection_tableview; + + @FXML + private TableColumn bill_no_col; + + @FXML + private TableColumn bill_amt_col; + + @FXML + private TableColumn supplier_col; + + @FXML + private TableColumn amount_collection_col; + + @FXML + private TableColumn bank_col; + + @FXML + private TableColumn dd_no_col; + + @FXML + private TableColumn dd_date_col; + + @FXML + private TextField bill_date; + + @FXML + private TextField bill_amount; + + @FXML + private ComboBox buyer_name; + + @FXML + private TextField supplier_name; + + @FXML + private ComboBox bill_no_combo; + + @FXML + private TextField bank_field; + + @FXML + private TextField total_amount_field; + + @FXML + private TextField amount_collected_field; + + @FXML + private TextField collection_due_field; + + @FXML + private Label last_voucher_field; + + @Override + public void initialize(URL url, ResourceBundle rb) { + collectionItemList = new ArrayList<>(); + buyerNameComboList = new ArrayList<>(); + billNoComboList = new ArrayList<>(); + bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); + bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); + supplier_col.setCellValueFactory(new PropertyValueFactory<>("supplierName")); + amount_collection_col.setCellValueFactory(new PropertyValueFactory<>("amountCollected")); + dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); + bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); + dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); + refreshCollectionTableView(); + fillBuyerNameCombo(); + updateLastVoucher(); + } + + private void refreshCollectionTableView() { + collection_tableview.setItems(FXCollections.observableArrayList(collectionItemList)); + } + + private void fillBuyerNameCombo() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "select Name from `Buyer_Master_Table` order by name collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + ResultSet buyerMasterResultSet = preparedStatement.executeQuery(); + + buyerNameComboList.clear(); + while (buyerMasterResultSet.next()) { + buyerNameComboList.add(buyerMasterResultSet.getString("Name")); + } + + buyer_name.setItems(FXCollections.observableArrayList(buyerNameComboList)); + + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void fillBillNoCombo() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + + String getCollectionAmountsForEveryoneSql = + "select `Bill No.`, sum(`Amount Collected`) as `Amount Collected` " + + "from `Collection_Entry_Extended_Table` group by `Bill No.`"; + Map collectionAmountMap = new HashMap<>(); + PreparedStatement preparedStatement = connection.prepareStatement(getCollectionAmountsForEveryoneSql); + ResultSet collectionAmountsResultSet = preparedStatement.executeQuery(); + while (collectionAmountsResultSet.next()) { + String amountCollectedStr = collectionAmountsResultSet.getString("Amount Collected"); + double amountCollected = 0; + try { + amountCollected = Double.parseDouble(amountCollectedStr); + } catch (NumberFormatException ex) { + logger.log(Level.SEVERE, ex.toString(), ex); + Utils.showAlert(ex.toString()); + } + collectionAmountMap.put(collectionAmountsResultSet.getString("Bill No."), amountCollected); + } + + String getBillAmountsForBuyerSql = "select `Bill No.`, `Bill Amount` from `Bill_Entry_Table` " + + "where `Buyer Name`=? order by `Bill No.` collate nocase"; + + preparedStatement = connection.prepareStatement(getBillAmountsForBuyerSql); + preparedStatement.setString(1, buyer_name.getValue()); + ResultSet billNoResultSet = preparedStatement.executeQuery(); + + billNoComboList.clear(); + + while (billNoResultSet.next()) { + String billNo = billNoResultSet.getString("Bill No."); + String billAmountStr = billNoResultSet.getString("Bill Amount"); + double billAmount = 1.0; + try { + billAmount = Double.parseDouble(billAmountStr); + } catch (NumberFormatException ex) { + logger.log(Level.SEVERE, ex.toString(), ex); + Utils.showAlert(ex.toString()); + } + if (collectionAmountMap.containsKey(billNo)) { + if (billAmount - collectionAmountMap.get(billNo) > 0) { + billNoComboList.add(billNo); + } + } else { + billNoComboList.add(billNo); + } + } + + bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList)); + + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void fetchData() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "Select * from Bill_Entry_Table where `Bill No.`=?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, bill_no_combo.getValue()); + ResultSet billResultSet = preparedStatement.executeQuery(); + String supplierName = billResultSet.getString("Supplier Name"); + String billDate = billResultSet.getString("Bill Date"); + String billAmount = billResultSet.getString("Bill Amount"); + previouslyDue = Integer.parseInt(billResultSet.getString("Collection Due")); + supplier_name.setText(supplierName); + bill_date.setText(billDate); + bill_amount.setText(billAmount); + updateCollectionDue(); + // buyer_name.setDisable(true); + billResultSet.close(); + + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void addCollection(ActionEvent ignoredEvent) { + if (bill_no_combo.getValue().isEmpty() + || bill_amount.getText().isEmpty() + || buyer_name.getValue().isEmpty() + || supplier_name.getText().isEmpty() + || bank_field.getText().isEmpty() + || collection_due_field.getText().isEmpty() + || amount_collected_field.getText().isEmpty() + || dd_no_field.getText().isEmpty() + || dd_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Please check whether the fields are properly filled or not.", 2); + return; + } + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + + collectionItemList.add(new CollectionItem( + bill_no_combo.getValue(), + bill_date.getText(), + bill_amount.getText(), + supplier_name.getText(), + collection_due_field.getText(), + amount_collected_field.getText(), + bank_field.getText(), + dd_no_field.getText(), + dateTimeFormatter.format(dd_date_field.getValue()))); + + refreshCollectionTableView(); + updateTotalAmount(); + clearRepeatingFields(); + } + + @FXML + private void updateCollectionDue() { + collection_due_field.setText( + Integer.toString(previouslyDue - Integer.parseInt(amount_collected_field.getText()))); + } + + private void updateTotalAmount() { + int totalAmount = 0; + for (CollectionItem collectionItem : collectionItemList) { + totalAmount += Integer.parseInt(collectionItem.getAmountCollected()); + } + total_amount_field.setText(Integer.toString(totalAmount)); + } + + private void clearRepeatingFields() { + bill_date.setText(""); + supplier_name.setText(""); + bill_amount.setText(""); + collection_due_field.setText("0"); + amount_collected_field.setText("0"); + bank_field.setText(""); + dd_no_field.setText(""); + + dd_date_field.setValue(null); + } + + @FXML + private void replaceCollection(ActionEvent ignoredEvent) { + if (collection_tableview.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the Collection Table", 2); + return; + } + if (bill_no_combo.getValue().isEmpty() + || bill_amount.getText().isEmpty() + || buyer_name.getValue().isEmpty() + || supplier_name.getText().isEmpty() + || bank_field.getText().isEmpty() + || collection_due_field.getText().isEmpty() + || amount_collected_field.getText().isEmpty() + || dd_no_field.getText().isEmpty() + || dd_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Please check whether the fields are properly filled or not.", 2); + return; + } + collectionItemList.set( + collection_tableview.getSelectionModel().getSelectedIndex(), + CollectionItem.builder() + .billNo(bill_no_combo.getValue()) + .billDate(bill_date.getText()) + .billAmount(bill_amount.getText()) + .supplierName(supplier_name.getText()) + .due(collection_due_field.getText()) + .amountCollected(amount_collected_field.getText()) + .bank(bank_field.getText()) + .ddNo(dd_no_field.getText()) + .ddDate(dd_date_field.getValue().toString()) + .build()); + refreshCollectionTableView(); + updateTotalAmount(); + } + + @FXML + private void deleteCollection(ActionEvent ignoredEvent) { + if (collection_tableview.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the LR Table", 2); + return; + } + collectionItemList.remove(collection_tableview.getSelectionModel().getSelectedIndex()); + refreshCollectionTableView(); + updateTotalAmount(); + } + + @FXML + private void clearAllFields() { + clearRepeatingFields(); + voucher_no_field.setText(""); + voucher_date_field.setValue(null); + buyer_name.setDisable(false); + billNoComboList.clear(); + } + + @FXML + private void saveData(ActionEvent ignoredEvent) { + Alert alert = new Alert( + Alert.AlertType.CONFIRMATION, + "Are you sure that you want save " + voucher_no_field.getText() + " ?", + ButtonType.YES, + ButtonType.NO, + ButtonType.CANCEL); + alert.showAndWait(); + + if (alert.getResult() != ButtonType.YES) { + return; + } + if (voucher_no_field.getText().isEmpty() + || voucher_date_field.getValue() == null + || voucher_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Check whether the Voucher No. and the Voucher Date is properly filled", 2); + return; + } + Connection connection = DatabaseHandler.getInstance().getConnection(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + try { + connection.setAutoCommit(false); + String sql = + "INSERT INTO `Collection_Entry_Table`(`Voucher No.`,`Voucher Date`,`Buyer Name`,`Total Amount`) VALUES (?,?,?,?)"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.setString(2, dateTimeFormatter.format(voucher_date_field.getValue())); + preparedStatement.setString(3, buyer_name.getValue()); + preparedStatement.setString(4, total_amount_field.getText()); + preparedStatement.execute(); + + for (CollectionItem collectionItem : collectionItemList) { + sql = + "INSERT INTO `Collection_Entry_Extended_Table`(`Voucher No.`,`Supplier Name`,`Bill No.`,`Bill Date`,`Bill Amount`,`Collection Due`,`Amount Collected`,`Bank`,`DD No.`,`DD Date`) VALUES (?,?,?,?,?,?,?,?,?,?);"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.setString(2, collectionItem.getSupplierName()); + preparedStatement.setString(3, collectionItem.getBillNo()); + preparedStatement.setString(4, collectionItem.getBillDate()); + preparedStatement.setString(5, collectionItem.getBillAmount()); + preparedStatement.setString(6, collectionItem.getDue()); + preparedStatement.setString(7, collectionItem.getAmountCollected()); + preparedStatement.setString(8, collectionItem.getBank()); + preparedStatement.setString(9, collectionItem.getDdNo()); + preparedStatement.setString(10, collectionItem.getDdDate()); + + preparedStatement.execute(); + + // Update Bill Entry Table + sql = "UPDATE `Bill_Entry_Table` SET `Collection Due`=? WHERE `BILL NO.`=?"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, collectionItem.getDue()); + preparedStatement.setString(2, collectionItem.getBillNo()); + preparedStatement.execute(); + } + connection.commit(); + Utils.showAlert("Saved Successfully", 1); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + try { + connection.rollback(); + } catch (SQLException ex1) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex1.toString(), ex1); + } + } + clearAllFields(); + collectionItemList.clear(); + refreshCollectionTableView(); + } + + private void updateLastVoucher() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "SELECT MAX(`Voucher No.`) from `COLLECTION_ENTRY_TABLE`;"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + ResultSet resultSet = preparedStatement.executeQuery(); + String answer = resultSet.getString("Max(`Voucher No.`)"); + last_voucher_field.setText("Last Voucher No. : " + answer); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString(), ex); + } + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/CollectionEntryController.java b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/CollectionEntryController.java index 19643f4..987a63a 100644 --- a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/CollectionEntryController.java +++ b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/CollectionEntryController.java @@ -1,12 +1,11 @@ -package satyamconsignment.ui.Input.CollectionEntry; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.fxml.Initializable; - -public class CollectionEntryController implements Initializable { - - @Override - public void initialize(URL location, ResourceBundle resources) { - } -} +package satyamconsignment.ui.Input.CollectionEntry; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.fxml.Initializable; + +public class CollectionEntryController implements Initializable { + + @Override + public void initialize(URL location, ResourceBundle resources) {} +} diff --git a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/ViewAndDeleteCollection/ViewAndDeleteCollection.java b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/ViewAndDeleteCollection/ViewAndDeleteCollection.java index 8f627c1..702f8f1 100644 --- a/src/main/java/satyamconsignment/ui/Input/CollectionEntry/ViewAndDeleteCollection/ViewAndDeleteCollection.java +++ b/src/main/java/satyamconsignment/ui/Input/CollectionEntry/ViewAndDeleteCollection/ViewAndDeleteCollection.java @@ -1,216 +1,228 @@ -package satyamconsignment.ui.Input.CollectionEntry.ViewAndDeleteCollection; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import net.sf.jasperreports.engine.*; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.model.CollectionItem; - -public class ViewAndDeleteCollection implements Initializable { - private List collectionItemList; - - @FXML - private TextField voucher_no_field; - @FXML - private TableView collection_tableview; - @FXML - private TableColumn bill_no_col; - @FXML - private TableColumn bill_amt_col; - @FXML - private TableColumn supplier_col; - @FXML - private TableColumn amount_collection_col; - @FXML - private TableColumn bank_col; - @FXML - private TableColumn dd_no_col; - @FXML - private TableColumn dd_date_col; - - @FXML - private Label display_board_label; - @FXML - private TextField total_amount_field; - @FXML - private Button get_details_btn; - @FXML - private Button delete_entry_btn; - - @FXML - private TableColumn bill_date_col; - @FXML - private TextField voucher_date; - @FXML - private TextField buyer_name; - - @FXML - private Button print_btn; - - @Override - public void initialize(URL url, ResourceBundle rb) { - collectionItemList = FXCollections.observableArrayList(); - - bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); - bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); - supplier_col.setCellValueFactory(new PropertyValueFactory<>("supplierName")); - bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); - amount_collection_col.setCellValueFactory(new PropertyValueFactory<>("amountCollected")); - dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); - bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); - dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); - } - - @FXML - private void getDetails(ActionEvent event) { - - if (voucher_no_field.getText().isEmpty()) { - Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no."); - return; - } - Connection connection = DatabaseHandler.getInstance().getConnection(); - try { - String sql = "select * from `Collection_Entry_Table` where `Voucher No.`=? collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - ResultSet collectionResultSet = preparedStatement.executeQuery(); - if (collectionResultSet.isClosed()) { - Utils.showAlert("No Results found", 1); - return; - } - - voucher_date.setText(collectionResultSet.getString("Voucher Date")); - buyer_name.setText(collectionResultSet.getString("Buyer Name")); - total_amount_field.setText(collectionResultSet.getString("Total Amount")); - display_board_label.setText(collectionResultSet.getString("Buyer Name")); - - collectionItemList.clear(); - sql = "select * from `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - collectionResultSet = preparedStatement.executeQuery(); - if (collectionResultSet.isClosed()) { - Utils.showAlert("No Results found", 1); - return; - } - while (collectionResultSet.next()) { - collectionItemList.add(new CollectionItem(collectionResultSet.getString("Bill No."), - collectionResultSet.getString("Bill Date"), - collectionResultSet.getString("Bill Amount"), - collectionResultSet.getString("Supplier Name"), - collectionResultSet.getString("collection due"), - collectionResultSet.getString("amount collected"), - collectionResultSet.getString("bank"), - collectionResultSet.getString("DD No."), - collectionResultSet.getString("DD Date"))); - } - collection_tableview.setItems(FXCollections.observableArrayList(collectionItemList)); - delete_entry_btn.setDisable(false); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - } - - @FXML - private void deleteEntry(ActionEvent event) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION, - "Are you sure that you want delete " + voucher_no_field.getText() + " ?", - ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - alert.showAndWait(); - - if (alert.getResult() != ButtonType.YES) { - return; - } - - Connection connection = DatabaseHandler.getInstance().getConnection(); - - try { - connection.setAutoCommit(false); - String sql = "SELECT `Bill No.`,`Amount Collected` FROM `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - sql = "UPDATE `Bill_Entry_Table` SET `Collection Due`=`Collection Due`+? WHERE `BILL NO.`=?"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, rs.getString("Amount Collected")); - preparedStatement.setString(2, rs.getString("Bill No.")); - preparedStatement.execute(); - } - - sql = "DELETE FROM `Collection_Entry_Table` where `Voucher No.`=? collate nocase"; - - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.execute(); - - sql = "DELETE FROM `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.execute(); - collectionItemList.clear(); - voucher_date.setText(""); - buyer_name.setText(""); - display_board_label.setText(""); - total_amount_field.setText(""); - connection.commit(); - Utils.showAlert( - voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", - 1); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - try { - connection.rollback(); - } catch (SQLException ex1) { - Utils.showAlert(ex1.toString()); - Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, - ex.toString(), ex1); - } - } - } - - @FXML - private void printCollection(ActionEvent event) { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String jrxmlFileName = "/satyamconsignment/ui/Input/CollectionEntry/Collection.jrxml"; - JasperReport jasperReport = JasperCompileManager - .compileReport(getClass().getResourceAsStream(jrxmlFileName)); - Map map = new HashMap<>(); - map.put("voucherNo", voucher_no_field.getText()); - map.put("voucherDate", voucher_date.getText()); - map.put("buyerName", buyer_name.getText()); - map.put("billAmount", total_amount_field.getText()); - JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, connection); - JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); - Utils.showAlert("Report Successfully Generated", 1); - } catch (JRException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } -} +package satyamconsignment.ui.Input.CollectionEntry.ViewAndDeleteCollection; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import net.sf.jasperreports.engine.*; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.CollectionItem; + +public class ViewAndDeleteCollection implements Initializable { + private List collectionItemList; + + @FXML + private TextField voucher_no_field; + + @FXML + private TableView collection_tableview; + + @FXML + private TableColumn bill_no_col; + + @FXML + private TableColumn bill_amt_col; + + @FXML + private TableColumn supplier_col; + + @FXML + private TableColumn amount_collection_col; + + @FXML + private TableColumn bank_col; + + @FXML + private TableColumn dd_no_col; + + @FXML + private TableColumn dd_date_col; + + @FXML + private Label display_board_label; + + @FXML + private TextField total_amount_field; + + @FXML + private Button get_details_btn; + + @FXML + private Button delete_entry_btn; + + @FXML + private TableColumn bill_date_col; + + @FXML + private TextField voucher_date; + + @FXML + private TextField buyer_name; + + @FXML + private Button print_btn; + + @Override + public void initialize(URL url, ResourceBundle rb) { + collectionItemList = FXCollections.observableArrayList(); + + bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); + bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); + supplier_col.setCellValueFactory(new PropertyValueFactory<>("supplierName")); + bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); + amount_collection_col.setCellValueFactory(new PropertyValueFactory<>("amountCollected")); + dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); + bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); + dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); + } + + @FXML + private void getDetails(ActionEvent event) { + + if (voucher_no_field.getText().isEmpty()) { + Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no."); + return; + } + Connection connection = DatabaseHandler.getInstance().getConnection(); + try { + String sql = "select * from `Collection_Entry_Table` where `Voucher No.`=? collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + ResultSet collectionResultSet = preparedStatement.executeQuery(); + if (collectionResultSet.isClosed()) { + Utils.showAlert("No Results found", 1); + return; + } + + voucher_date.setText(collectionResultSet.getString("Voucher Date")); + buyer_name.setText(collectionResultSet.getString("Buyer Name")); + total_amount_field.setText(collectionResultSet.getString("Total Amount")); + display_board_label.setText(collectionResultSet.getString("Buyer Name")); + + collectionItemList.clear(); + sql = "select * from `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + collectionResultSet = preparedStatement.executeQuery(); + if (collectionResultSet.isClosed()) { + Utils.showAlert("No Results found", 1); + return; + } + while (collectionResultSet.next()) { + collectionItemList.add(new CollectionItem( + collectionResultSet.getString("Bill No."), + collectionResultSet.getString("Bill Date"), + collectionResultSet.getString("Bill Amount"), + collectionResultSet.getString("Supplier Name"), + collectionResultSet.getString("collection due"), + collectionResultSet.getString("amount collected"), + collectionResultSet.getString("bank"), + collectionResultSet.getString("DD No."), + collectionResultSet.getString("DD Date"))); + } + collection_tableview.setItems(FXCollections.observableArrayList(collectionItemList)); + delete_entry_btn.setDisable(false); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void deleteEntry(ActionEvent event) { + Alert alert = new Alert( + Alert.AlertType.CONFIRMATION, + "Are you sure that you want delete " + voucher_no_field.getText() + " ?", + ButtonType.YES, + ButtonType.NO, + ButtonType.CANCEL); + alert.showAndWait(); + + if (alert.getResult() != ButtonType.YES) { + return; + } + + Connection connection = DatabaseHandler.getInstance().getConnection(); + + try { + connection.setAutoCommit(false); + String sql = + "SELECT `Bill No.`,`Amount Collected` FROM `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + ResultSet rs = preparedStatement.executeQuery(); + while (rs.next()) { + sql = "UPDATE `Bill_Entry_Table` SET `Collection Due`=`Collection Due`+? WHERE `BILL NO.`=?"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, rs.getString("Amount Collected")); + preparedStatement.setString(2, rs.getString("Bill No.")); + preparedStatement.execute(); + } + + sql = "DELETE FROM `Collection_Entry_Table` where `Voucher No.`=? collate nocase"; + + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.execute(); + + sql = "DELETE FROM `Collection_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.execute(); + collectionItemList.clear(); + voucher_date.setText(""); + buyer_name.setText(""); + display_board_label.setText(""); + total_amount_field.setText(""); + connection.commit(); + Utils.showAlert(voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", 1); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, ex.toString(), ex); + try { + connection.rollback(); + } catch (SQLException ex1) { + Utils.showAlert(ex1.toString()); + Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, ex.toString(), ex1); + } + } + } + + @FXML + private void printCollection(ActionEvent event) { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String jrxmlFileName = "/satyamconsignment/ui/Input/CollectionEntry/Collection.jrxml"; + JasperReport jasperReport = + JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFileName)); + Map map = new HashMap<>(); + map.put("voucherNo", voucher_no_field.getText()); + map.put("voucherDate", voucher_date.getText()); + map.put("buyerName", buyer_name.getText()); + map.put("billAmount", total_amount_field.getText()); + JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, connection); + JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); + Utils.showAlert("Report Successfully Generated", 1); + } catch (JRException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(ViewAndDeleteCollection.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/InputController.java b/src/main/java/satyamconsignment/ui/Input/InputController.java index eaa84cb..48ec5bf 100644 --- a/src/main/java/satyamconsignment/ui/Input/InputController.java +++ b/src/main/java/satyamconsignment/ui/Input/InputController.java @@ -1,46 +1,47 @@ -package satyamconsignment.ui.Input; - -import java.net.URL; -import java.util.ResourceBundle; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.Group; -import javafx.scene.control.Button; -import satyamconsignment.common.ViewLoader; - -public class InputController implements Initializable { - - @FXML - private Button bill_entry_btn; - @FXML - private Button collection_entry_brn; - @FXML - private Button payment_entry_btn; - @FXML - private Group root; - - private ViewLoader viewLoader; - - @Override - public void initialize(URL url, ResourceBundle rb) { - viewLoader = new ViewLoader(); - } - - @FXML - private void showBillEntryScreen(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Input/BillEntry/BillEntry.fxml", root); - } - - @FXML - private void showCollectionEntryScreen(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Input/CollectionEntry/CollectionEntry.fxml", - root); - } - - @FXML - private void showPaymentEntryScreen(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Input/PaymentEntry/PaymentEntry.fxml", root); - } -} +package satyamconsignment.ui.Input; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Group; +import javafx.scene.control.Button; +import satyamconsignment.common.ViewLoader; + +public class InputController implements Initializable { + + @FXML + private Button bill_entry_btn; + + @FXML + private Button collection_entry_brn; + + @FXML + private Button payment_entry_btn; + + @FXML + private Group root; + + private ViewLoader viewLoader; + + @Override + public void initialize(URL url, ResourceBundle rb) { + viewLoader = new ViewLoader(); + } + + @FXML + private void showBillEntryScreen(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Input/BillEntry/BillEntry.fxml", root); + } + + @FXML + private void showCollectionEntryScreen(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Input/CollectionEntry/CollectionEntry.fxml", root); + } + + @FXML + private void showPaymentEntryScreen(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Input/PaymentEntry/PaymentEntry.fxml", root); + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/AddPayment/AddPayment.java b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/AddPayment/AddPayment.java index 620d471..f257584 100644 --- a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/AddPayment/AddPayment.java +++ b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/AddPayment/AddPayment.java @@ -1,400 +1,442 @@ -package satyamconsignment.ui.Input.PaymentEntry.AddPayment; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.text.Text; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController; -import satyamconsignment.model.PaymentItem; - -public class AddPayment implements Initializable { - - private List paymentItems; - private List supplierNameComboList; - private List billNoComboList; - private int previouslyDue; - - private static final Logger logger = Logger.getLogger(AddPayment.class.getName()); - - @FXML - private TextField dd_no_field; - @FXML - private DatePicker dd_date_field; - @FXML - private DatePicker voucher_date_field; - @FXML - private TextField voucher_no_field; - @FXML - private Button add_payment_btn; - @FXML - private Button replace_payment_btn; - @FXML - private Button delete_payment_btn; - @FXML - private TableColumn bill_no_col; - @FXML - private TableColumn bill_amt_col; - @FXML - private TableColumn dd_no_col; - @FXML - private TableColumn dd_date_col; - @FXML - private TableColumn bill_dt_col; - @FXML - private TableColumn buyer_col; - @FXML - private TableColumn due_col; - @FXML - private TableColumn amount_paid_col; - @FXML - private TableView payment_tableview; - @FXML - private TextField amount_paid_field; - @FXML - private TextField buyer_name_field; - @FXML - private TextField bill_date_field; - @FXML - private TextField bill_amount_field; - - @FXML - private ComboBox supplier_name_combo; - @FXML - private ComboBox bill_no_combo; - @FXML - private TextField due_amount_field; - @FXML - private TableColumn bank_col; - @FXML - private TextField bank_field; - @FXML - private TextField total_amount_paid_field; - @FXML - private Button save_btn; - @FXML - private Button clear_btn; - - @FXML - private Text last_voucher_field; - - @Override - public void initialize(URL url, ResourceBundle rb) { - paymentItems = new ArrayList<>(); - supplierNameComboList = new ArrayList<>(); - billNoComboList = new ArrayList<>(); - - bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); - bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); - bill_dt_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); - buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName")); - bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); - dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); - dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); - due_col.setCellValueFactory(new PropertyValueFactory<>("due")); - amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid")); - - refreshPaymentTableView(); - fillSupplierCombo(); - - updateLastVoucher(); - } - - private void refreshPaymentTableView() { - payment_tableview.setItems(FXCollections.observableArrayList(paymentItems)); - } - - @FXML - private void addPayment(ActionEvent ignoredEvent) { - if (bill_no_combo.getValue().isEmpty() || bill_amount_field.getText().isEmpty() - || buyer_name_field.getText().isEmpty() || supplier_name_combo.getValue().isEmpty() - || bank_field.getText().isEmpty() || bank_field.getText().isEmpty() - || due_amount_field.getText().isEmpty() || amount_paid_field.getText().isEmpty() - || dd_no_field.getText().isEmpty() - || dd_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Please check whether the fields are properly filled or not.", 2); - return; - } - - DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern(Constants.DATE_TIME_FORMAT); - - paymentItems.add(new PaymentItem(bill_no_combo.getValue(), bill_amount_field.getText(), - bill_date_field.getText(), buyer_name_field.getText(), due_amount_field.getText(), - amount_paid_field.getText(), bank_field.getText(), dd_no_field.getText(), - dateTimeFormatter.format(dd_date_field.getValue()))); - - refreshPaymentTableView(); - - clearRepeatingFields(); - updateTotalAmountPaid(); - } - - @FXML - private void replacePayment(ActionEvent ignoredEvent) { - - if (payment_tableview.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the Payment Table", 2); - return; - } - - if (bill_no_combo.getValue().isEmpty() || bill_amount_field.getText().isEmpty() - || buyer_name_field.getText().isEmpty() || supplier_name_combo.getValue().isEmpty() - || bank_field.getText().isEmpty() || bank_field.getText().isEmpty() - || due_amount_field.getText().isEmpty() || amount_paid_field.getText().isEmpty() - || dd_no_field.getText().isEmpty() - || dd_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Please check whether the fields are properly filled or not.", 2); - return; - } - - DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern(Constants.DATE_TIME_FORMAT); - - paymentItems.set(payment_tableview.getSelectionModel().getSelectedIndex(), - new PaymentItem(bill_no_combo.getValue(), bill_amount_field.getText(), - bill_date_field.getText(), buyer_name_field.getText(), - due_amount_field.getText(), amount_paid_field.getText(), - bank_field.getText(), dd_no_field.getText(), - dateTimeFormatter.format(dd_date_field.getValue()))); - - refreshPaymentTableView(); - - clearRepeatingFields(); - updateTotalAmountPaid(); - } - - @FXML - private void deletePayment(ActionEvent ignoredEvent) { - if (payment_tableview.getSelectionModel().getSelectedIndex() == -1) { - Utils.showAlert("Please select an item from the Payment Table", 2); - return; - } - paymentItems.remove(payment_tableview.getSelectionModel().getSelectedIndex()); - refreshPaymentTableView(); - updateTotalAmountPaid(); - } - - private void clearRepeatingFields() { - bill_date_field.setText(""); - buyer_name_field.setText(""); - bill_amount_field.setText("0"); - due_amount_field.setText("0"); - amount_paid_field.setText("0"); - bank_field.setText(""); - dd_no_field.setText(""); - dd_date_field.setValue(null); - } - - private void updateTotalAmountPaid() { - int totalAmountPaid = 0; - for (PaymentItem paymentItem : paymentItems) { - totalAmountPaid += Integer.parseInt(paymentItem.getAmountPaid()); - } - total_amount_paid_field.setText(Integer.toString(totalAmountPaid)); - } - - @FXML - private void clearAllFields() { - clearRepeatingFields(); - voucher_no_field.setText(""); - voucher_date_field.setValue(null); - supplier_name_combo.setDisable(false); - billNoComboList.clear(); - } - - @FXML - private void saveData(ActionEvent ignoredEvent) { - if (voucher_no_field.getText().isEmpty() - || voucher_date_field.getValue().toString().isEmpty()) { - Utils.showAlert("Check whether the Voucher No. and the Voucher Date is properly filled", - 2); - return; - } - Connection connection = DatabaseHandler.getInstance().getConnection(); - DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern(Constants.DATE_TIME_FORMAT); - try { - connection.setAutoCommit(false); - String sql = "INSERT INTO `Payment_Entry_Table`(`Voucher No.`,`Voucher Date`,`Supplier Name`,`Total Amount`) VALUES (?,?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.setString(2, dateTimeFormatter.format(voucher_date_field.getValue())); - preparedStatement.setString(3, supplier_name_combo.getValue()); - preparedStatement.setString(4, total_amount_paid_field.getText()); - preparedStatement.execute(); - - for (PaymentItem paymentItem : paymentItems) { - sql = "INSERT INTO `Payment_Entry_Extended_Table`(`Voucher No.`,`Buyer Name`,`Bill No.`,`Bill Date`,`Bill Amount`,`Due Amount`,`Amount Paid`,`Bank`,`DD No.`,`DD Date`) VALUES (?,?,?,?,?,?,?,?,?,?)"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, voucher_no_field.getText()); - preparedStatement.setString(2, paymentItem.getBuyerName()); - preparedStatement.setString(3, paymentItem.getBillNo()); - preparedStatement.setString(4, paymentItem.getBillDate()); - preparedStatement.setString(5, paymentItem.getBillAmount()); - preparedStatement.setString(6, paymentItem.getDue()); - preparedStatement.setString(7, paymentItem.getAmountPaid()); - preparedStatement.setString(8, paymentItem.getBank()); - preparedStatement.setString(9, paymentItem.getDdNo()); - preparedStatement.setString(10, paymentItem.getDdDate()); - - preparedStatement.execute(); - - // Update Bill Entry Table - sql = "UPDATE `Bill_Entry_Table` SET `Due`=? WHERE `BILL NO.`=?"; - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, paymentItem.getDue()); - preparedStatement.setString(2, paymentItem.getBillNo()); - preparedStatement.execute(); - } - connection.commit(); - Utils.showAlert("Saved Successfully", 1); - clearAllFields(); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - try { - connection.rollback(); - } catch (SQLException ex1) { - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, - ex1); - } - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex); - } - paymentItems.clear(); - refreshPaymentTableView(); - } - - private void updateLastVoucher() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "SELECT MAX(`Voucher No.`) from `PAYMENT_ENTRY_TABLE`;"; - PreparedStatement ps = connection.prepareStatement(sql); - ResultSet resultSet = ps.executeQuery(); - String lastVoucherNo = resultSet.getString("Max(`Voucher No.`)"); - last_voucher_field.setText("Last Voucher No. : " + lastVoucherNo); - } catch (SQLException ex) { - logger.log(Level.SEVERE, "Failed to update Last Payment Voucher", ex); - } - } - - private void fillSupplierCombo() { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "select Name from `Supplier_Master_Table` order by name collate nocase"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - ResultSet resultSet = preparedStatement.executeQuery(); - - supplierNameComboList.clear(); - while (resultSet.next()) { - supplierNameComboList.add(resultSet.getString("Name")); - } - supplier_name_combo.setItems(FXCollections.observableArrayList(supplierNameComboList)); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, "Failed to populate the supplier combo", ex); - } - } - - @FXML - private void fillBillNoCombo(ActionEvent ignoredEvent) { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - - String getPaymentAmountsForEveryoneSql = "select `Bill No.`, sum(`Amount Paid`) as `Amount Paid` " - + "from `Payment_Entry_Extended_Table` group by `Bill No.`"; - Map paymentAmountMap = new HashMap<>(); - PreparedStatement preparedStatement = connection - .prepareStatement(getPaymentAmountsForEveryoneSql); - ResultSet paidAmountsResultSet = preparedStatement.executeQuery(); - while (paidAmountsResultSet.next()) { - String amountPaidStr = paidAmountsResultSet.getString("Amount Paid"); - double amountPaid = 0; - try { - amountPaid = Double.parseDouble(amountPaidStr); - } catch (NumberFormatException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString()); - } - paymentAmountMap.put(paidAmountsResultSet.getString("Bill No."), amountPaid); - } - - String sql = "SELECT `Bill No.`, `Bill Amount` FROM `Bill_Entry_Table` where `Supplier Name`=? " - + "order by `Bill No.` collate nocase"; - - preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, - supplier_name_combo.getSelectionModel().getSelectedItem()); - ResultSet billNoResultSet = preparedStatement.executeQuery(); - - billNoComboList.clear(); - while (billNoResultSet.next()) { - String billNo = billNoResultSet.getString("Bill No."); - String billAmountStr = billNoResultSet.getString("Bill Amount"); - double billAmount = 1.0; - try { - billAmount = Double.parseDouble(billAmountStr); - } catch (NumberFormatException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, ex.toString()); - } - if (paymentAmountMap.containsKey(billNo)) { - if (billAmount - paymentAmountMap.get(billNo) > 0) { - billNoComboList.add(billNo); - } - } else { - billNoComboList.add(billNo); - } - } - bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList)); - - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, "Failed to populate bill number combo", ex); - } - } - - @FXML - private void fetchData(ActionEvent ignoredEvent) { - try { - Connection connection = DatabaseHandler.getInstance().getConnection(); - String sql = "Select * from Bill_Entry_Table where `Bill No.`=?"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setString(1, bill_no_combo.getValue()); - ResultSet resultSet = preparedStatement.executeQuery(); - buyer_name_field.setText(resultSet.getString("Buyer Name")); - bill_date_field.setText(resultSet.getString("Bill Date")); - bill_amount_field.setText(resultSet.getString("Bill Amount")); - previouslyDue = Integer.parseInt(resultSet.getString("Due")); - updateDueAmount(); -// supplier_name_combo.setDisable(true); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - logger.log(Level.SEVERE, "Failed to fetch data", ex); - } - } - - @FXML - private void updateDueAmount() { - int amountPaid = 0; - try { - amountPaid = Integer.parseInt(amount_paid_field.getText()); - } catch (Exception ex) { - logger.log(Level.WARNING, "cannot be converted to integer"); - } - due_amount_field.setText(Integer.toString(previouslyDue - amountPaid)); - } -} +package satyamconsignment.ui.Input.PaymentEntry.AddPayment; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.text.Text; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.PaymentItem; +import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController; + +public class AddPayment implements Initializable { + + private List paymentItems; + private List supplierNameComboList; + private List billNoComboList; + private int previouslyDue; + + private static final Logger logger = Logger.getLogger(AddPayment.class.getName()); + + @FXML + private TextField dd_no_field; + + @FXML + private DatePicker dd_date_field; + + @FXML + private DatePicker voucher_date_field; + + @FXML + private TextField voucher_no_field; + + @FXML + private Button add_payment_btn; + + @FXML + private Button replace_payment_btn; + + @FXML + private Button delete_payment_btn; + + @FXML + private TableColumn bill_no_col; + + @FXML + private TableColumn bill_amt_col; + + @FXML + private TableColumn dd_no_col; + + @FXML + private TableColumn dd_date_col; + + @FXML + private TableColumn bill_dt_col; + + @FXML + private TableColumn buyer_col; + + @FXML + private TableColumn due_col; + + @FXML + private TableColumn amount_paid_col; + + @FXML + private TableView payment_tableview; + + @FXML + private TextField amount_paid_field; + + @FXML + private TextField buyer_name_field; + + @FXML + private TextField bill_date_field; + + @FXML + private TextField bill_amount_field; + + @FXML + private ComboBox supplier_name_combo; + + @FXML + private ComboBox bill_no_combo; + + @FXML + private TextField due_amount_field; + + @FXML + private TableColumn bank_col; + + @FXML + private TextField bank_field; + + @FXML + private TextField total_amount_paid_field; + + @FXML + private Button save_btn; + + @FXML + private Button clear_btn; + + @FXML + private Text last_voucher_field; + + @Override + public void initialize(URL url, ResourceBundle rb) { + paymentItems = new ArrayList<>(); + supplierNameComboList = new ArrayList<>(); + billNoComboList = new ArrayList<>(); + + bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); + bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); + bill_dt_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); + buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName")); + bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); + dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); + dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); + due_col.setCellValueFactory(new PropertyValueFactory<>("due")); + amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid")); + + refreshPaymentTableView(); + fillSupplierCombo(); + + updateLastVoucher(); + } + + private void refreshPaymentTableView() { + payment_tableview.setItems(FXCollections.observableArrayList(paymentItems)); + } + + @FXML + private void addPayment(ActionEvent ignoredEvent) { + if (bill_no_combo.getValue().isEmpty() + || bill_amount_field.getText().isEmpty() + || buyer_name_field.getText().isEmpty() + || supplier_name_combo.getValue().isEmpty() + || bank_field.getText().isEmpty() + || bank_field.getText().isEmpty() + || due_amount_field.getText().isEmpty() + || amount_paid_field.getText().isEmpty() + || dd_no_field.getText().isEmpty() + || dd_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Please check whether the fields are properly filled or not.", 2); + return; + } + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + + paymentItems.add(new PaymentItem( + bill_no_combo.getValue(), + bill_amount_field.getText(), + bill_date_field.getText(), + buyer_name_field.getText(), + due_amount_field.getText(), + amount_paid_field.getText(), + bank_field.getText(), + dd_no_field.getText(), + dateTimeFormatter.format(dd_date_field.getValue()))); + + refreshPaymentTableView(); + + clearRepeatingFields(); + updateTotalAmountPaid(); + } + + @FXML + private void replacePayment(ActionEvent ignoredEvent) { + + if (payment_tableview.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the Payment Table", 2); + return; + } + + if (bill_no_combo.getValue().isEmpty() + || bill_amount_field.getText().isEmpty() + || buyer_name_field.getText().isEmpty() + || supplier_name_combo.getValue().isEmpty() + || bank_field.getText().isEmpty() + || bank_field.getText().isEmpty() + || due_amount_field.getText().isEmpty() + || amount_paid_field.getText().isEmpty() + || dd_no_field.getText().isEmpty() + || dd_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Please check whether the fields are properly filled or not.", 2); + return; + } + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + + paymentItems.set( + payment_tableview.getSelectionModel().getSelectedIndex(), + new PaymentItem( + bill_no_combo.getValue(), + bill_amount_field.getText(), + bill_date_field.getText(), + buyer_name_field.getText(), + due_amount_field.getText(), + amount_paid_field.getText(), + bank_field.getText(), + dd_no_field.getText(), + dateTimeFormatter.format(dd_date_field.getValue()))); + + refreshPaymentTableView(); + + clearRepeatingFields(); + updateTotalAmountPaid(); + } + + @FXML + private void deletePayment(ActionEvent ignoredEvent) { + if (payment_tableview.getSelectionModel().getSelectedIndex() == -1) { + Utils.showAlert("Please select an item from the Payment Table", 2); + return; + } + paymentItems.remove(payment_tableview.getSelectionModel().getSelectedIndex()); + refreshPaymentTableView(); + updateTotalAmountPaid(); + } + + private void clearRepeatingFields() { + bill_date_field.setText(""); + buyer_name_field.setText(""); + bill_amount_field.setText("0"); + due_amount_field.setText("0"); + amount_paid_field.setText("0"); + bank_field.setText(""); + dd_no_field.setText(""); + dd_date_field.setValue(null); + } + + private void updateTotalAmountPaid() { + int totalAmountPaid = 0; + for (PaymentItem paymentItem : paymentItems) { + totalAmountPaid += Integer.parseInt(paymentItem.getAmountPaid()); + } + total_amount_paid_field.setText(Integer.toString(totalAmountPaid)); + } + + @FXML + private void clearAllFields() { + clearRepeatingFields(); + voucher_no_field.setText(""); + voucher_date_field.setValue(null); + supplier_name_combo.setDisable(false); + billNoComboList.clear(); + } + + @FXML + private void saveData(ActionEvent ignoredEvent) { + if (voucher_no_field.getText().isEmpty() + || voucher_date_field.getValue().toString().isEmpty()) { + Utils.showAlert("Check whether the Voucher No. and the Voucher Date is properly filled", 2); + return; + } + Connection connection = DatabaseHandler.getInstance().getConnection(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT); + try { + connection.setAutoCommit(false); + String sql = + "INSERT INTO `Payment_Entry_Table`(`Voucher No.`,`Voucher Date`,`Supplier Name`,`Total Amount`) VALUES (?,?,?,?)"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.setString(2, dateTimeFormatter.format(voucher_date_field.getValue())); + preparedStatement.setString(3, supplier_name_combo.getValue()); + preparedStatement.setString(4, total_amount_paid_field.getText()); + preparedStatement.execute(); + + for (PaymentItem paymentItem : paymentItems) { + sql = + "INSERT INTO `Payment_Entry_Extended_Table`(`Voucher No.`,`Buyer Name`,`Bill No.`,`Bill Date`,`Bill Amount`,`Due Amount`,`Amount Paid`,`Bank`,`DD No.`,`DD Date`) VALUES (?,?,?,?,?,?,?,?,?,?)"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, voucher_no_field.getText()); + preparedStatement.setString(2, paymentItem.getBuyerName()); + preparedStatement.setString(3, paymentItem.getBillNo()); + preparedStatement.setString(4, paymentItem.getBillDate()); + preparedStatement.setString(5, paymentItem.getBillAmount()); + preparedStatement.setString(6, paymentItem.getDue()); + preparedStatement.setString(7, paymentItem.getAmountPaid()); + preparedStatement.setString(8, paymentItem.getBank()); + preparedStatement.setString(9, paymentItem.getDdNo()); + preparedStatement.setString(10, paymentItem.getDdDate()); + + preparedStatement.execute(); + + // Update Bill Entry Table + sql = "UPDATE `Bill_Entry_Table` SET `Due`=? WHERE `BILL NO.`=?"; + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, paymentItem.getDue()); + preparedStatement.setString(2, paymentItem.getBillNo()); + preparedStatement.execute(); + } + connection.commit(); + Utils.showAlert("Saved Successfully", 1); + clearAllFields(); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + try { + connection.rollback(); + } catch (SQLException ex1) { + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex1); + } + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex); + } + paymentItems.clear(); + refreshPaymentTableView(); + } + + private void updateLastVoucher() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "SELECT MAX(`Voucher No.`) from `PAYMENT_ENTRY_TABLE`;"; + PreparedStatement ps = connection.prepareStatement(sql); + ResultSet resultSet = ps.executeQuery(); + String lastVoucherNo = resultSet.getString("Max(`Voucher No.`)"); + last_voucher_field.setText("Last Voucher No. : " + lastVoucherNo); + } catch (SQLException ex) { + logger.log(Level.SEVERE, "Failed to update Last Payment Voucher", ex); + } + } + + private void fillSupplierCombo() { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "select Name from `Supplier_Master_Table` order by name collate nocase"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + ResultSet resultSet = preparedStatement.executeQuery(); + + supplierNameComboList.clear(); + while (resultSet.next()) { + supplierNameComboList.add(resultSet.getString("Name")); + } + supplier_name_combo.setItems(FXCollections.observableArrayList(supplierNameComboList)); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, "Failed to populate the supplier combo", ex); + } + } + + @FXML + private void fillBillNoCombo(ActionEvent ignoredEvent) { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + + String getPaymentAmountsForEveryoneSql = "select `Bill No.`, sum(`Amount Paid`) as `Amount Paid` " + + "from `Payment_Entry_Extended_Table` group by `Bill No.`"; + Map paymentAmountMap = new HashMap<>(); + PreparedStatement preparedStatement = connection.prepareStatement(getPaymentAmountsForEveryoneSql); + ResultSet paidAmountsResultSet = preparedStatement.executeQuery(); + while (paidAmountsResultSet.next()) { + String amountPaidStr = paidAmountsResultSet.getString("Amount Paid"); + double amountPaid = 0; + try { + amountPaid = Double.parseDouble(amountPaidStr); + } catch (NumberFormatException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString()); + } + paymentAmountMap.put(paidAmountsResultSet.getString("Bill No."), amountPaid); + } + + String sql = "SELECT `Bill No.`, `Bill Amount` FROM `Bill_Entry_Table` where `Supplier Name`=? " + + "order by `Bill No.` collate nocase"; + + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString( + 1, supplier_name_combo.getSelectionModel().getSelectedItem()); + ResultSet billNoResultSet = preparedStatement.executeQuery(); + + billNoComboList.clear(); + while (billNoResultSet.next()) { + String billNo = billNoResultSet.getString("Bill No."); + String billAmountStr = billNoResultSet.getString("Bill Amount"); + double billAmount = 1.0; + try { + billAmount = Double.parseDouble(billAmountStr); + } catch (NumberFormatException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, ex.toString()); + } + if (paymentAmountMap.containsKey(billNo)) { + if (billAmount - paymentAmountMap.get(billNo) > 0) { + billNoComboList.add(billNo); + } + } else { + billNoComboList.add(billNo); + } + } + bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList)); + + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, "Failed to populate bill number combo", ex); + } + } + + @FXML + private void fetchData(ActionEvent ignoredEvent) { + try { + Connection connection = DatabaseHandler.getInstance().getConnection(); + String sql = "Select * from Bill_Entry_Table where `Bill No.`=?"; + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, bill_no_combo.getValue()); + ResultSet resultSet = preparedStatement.executeQuery(); + buyer_name_field.setText(resultSet.getString("Buyer Name")); + bill_date_field.setText(resultSet.getString("Bill Date")); + bill_amount_field.setText(resultSet.getString("Bill Amount")); + previouslyDue = Integer.parseInt(resultSet.getString("Due")); + updateDueAmount(); + // supplier_name_combo.setDisable(true); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + logger.log(Level.SEVERE, "Failed to fetch data", ex); + } + } + + @FXML + private void updateDueAmount() { + int amountPaid = 0; + try { + amountPaid = Integer.parseInt(amount_paid_field.getText()); + } catch (Exception ex) { + logger.log(Level.WARNING, "cannot be converted to integer"); + } + due_amount_field.setText(Integer.toString(previouslyDue - amountPaid)); + } +} diff --git a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/PaymentEntryController.java b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/PaymentEntryController.java index 9da0d0d..d2f5dda 100644 --- a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/PaymentEntryController.java +++ b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/PaymentEntryController.java @@ -1,12 +1,11 @@ -package satyamconsignment.ui.Input.PaymentEntry; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.fxml.Initializable; - -public class PaymentEntryController implements Initializable { - - @Override - public void initialize(URL location, ResourceBundle resources) { - } -} +package satyamconsignment.ui.Input.PaymentEntry; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.fxml.Initializable; + +public class PaymentEntryController implements Initializable { + + @Override + public void initialize(URL location, ResourceBundle resources) {} +} diff --git a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/ViewAndDeletePayment/ViewAndDeletePayment.java b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/ViewAndDeletePayment/ViewAndDeletePayment.java index b2a26c0..d440501 100644 --- a/src/main/java/satyamconsignment/ui/Input/PaymentEntry/ViewAndDeletePayment/ViewAndDeletePayment.java +++ b/src/main/java/satyamconsignment/ui/Input/PaymentEntry/ViewAndDeletePayment/ViewAndDeletePayment.java @@ -1,207 +1,226 @@ -package satyamconsignment.ui.Input.PaymentEntry.ViewAndDeletePayment; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; -import net.sf.jasperreports.engine.*; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; -import satyamconsignment.ui.Input.CollectionEntry.CollectionEntryController; -import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController; -import satyamconsignment.model.PaymentItem; - -public class ViewAndDeletePayment implements Initializable { - - @FXML - private TextField voucher_no_field; - @FXML - private TableColumn bill_no_col; - @FXML - private TableColumn bill_amt_col; - @FXML - private TableColumn bill_date_col; - @FXML - private TableColumn buyer_col; - @FXML - private TableColumn amount_paid_col; - @FXML - private TableColumn bank_col; - @FXML - private TableColumn dd_no_col; - @FXML - private TableColumn dd_date_col; - @FXML - private Label display_board_label; - @FXML - private TextField total_amount_field; - @FXML - private Button get_details_btn; - @FXML - private Button delete_entry_btn; - @FXML - private TextField voucher_date; - @FXML - private TextField supplier_name; - @FXML - private TableColumn due_col; - @FXML - private TableView payment_tableview; - @FXML - private Button print_payment_btn; - - @Override - public void initialize(URL url, ResourceBundle rb) { - bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); - bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); - buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName")); - bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); - due_col.setCellValueFactory(new PropertyValueFactory<>("due")); - amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid")); - dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); - bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); - dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); - } - - @FXML - private void getDetails(ActionEvent event) { - - if (voucher_no_field.getText().isEmpty()) { - Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no."); - return; - } - try { - String sql = "select * from `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; - Connection conn = DatabaseHandler.getInstance().getConnection(); - PreparedStatement ps = conn.prepareStatement(sql); - ps.setString(1, voucher_no_field.getText()); - ResultSet rs = ps.executeQuery(); - - voucher_date.setText(rs.getString("Voucher Date")); - supplier_name.setText(rs.getString("Supplier Name")); - total_amount_field.setText(rs.getString("Total Amount")); - display_board_label.setText(rs.getString("Supplier Name")); - - List list = new ArrayList<>(); - sql = "select * from `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - ps = conn.prepareStatement(sql); - ps.setString(1, voucher_no_field.getText()); - rs = ps.executeQuery(); - if (rs.isClosed()) { - Utils.showAlert("No Results found", 1); - } else { - while (rs.next()) { - PaymentItem paymentItem = PaymentItem.builder().billNo(rs.getString("Bill No.")) - .billAmount(rs.getString("Bill Amount")) - .billDate(rs.getString("Bill Date")) - .buyerName(rs.getString("Buyer Name")).due(rs.getString("due amount")) - .amountPaid(rs.getString("amount paid")).bank(rs.getString("bank")) - .ddNo(rs.getString("DD No.")).ddDate(rs.getString("DD Date")).build(); - - list.add(paymentItem); - } - payment_tableview.setItems(FXCollections.observableArrayList(list)); - delete_entry_btn.setDisable(false); - } - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(CollectionEntryController.class.getName()).log(Level.SEVERE, null, ex); - } - - } - - @FXML - private void deleteEntry(ActionEvent event) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION, - "Are you sure that you want delete " + voucher_no_field.getText() + " ?", - ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - alert.showAndWait(); - - if (alert.getResult() != ButtonType.YES) { - return; - } - - Connection conn = DatabaseHandler.getInstance().getConnection(); - - try { - conn.setAutoCommit(false); - String sql = "SELECT `Bill No.`,`Amount Paid` FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - PreparedStatement ps = conn.prepareStatement(sql); - ps.setString(1, voucher_no_field.getText()); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - sql = "UPDATE `Bill_Entry_Table` SET `Due`=`Due`+? WHERE `BILL NO.`=?"; - ps = conn.prepareStatement(sql); - ps.setString(1, rs.getString("Amount Paid")); - ps.setString(2, rs.getString("Bill No.")); - ps.execute(); - } - sql = "DELETE FROM `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; - ps = conn.prepareStatement(sql); - ps.setString(1, voucher_no_field.getText()); - ps.execute(); - - sql = "DELETE FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; - ps = conn.prepareStatement(sql); - ps.setString(1, voucher_no_field.getText()); - ps.execute(); - - payment_tableview.setItems(FXCollections.observableArrayList()); - - voucher_date.setText(""); - supplier_name.setText(""); - display_board_label.setText(""); - total_amount_field.setText(""); - conn.commit(); - Utils.showAlert( - voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", - 1); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - try { - conn.rollback(); - } catch (SQLException ex1) { - Utils.showAlert(ex1.toString()); - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, - ex1.toString(), ex1); - } - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - - } - - @FXML - private void printPayment(ActionEvent event) { - try { - Connection conn = DatabaseHandler.getInstance().getConnection(); - String jrxmlFileName = "/satyamconsignment/ui/Input/PaymentEntry/Payment.jrxml"; - JasperReport jasperReport = JasperCompileManager - .compileReport(getClass().getResourceAsStream(jrxmlFileName)); - Map map = new HashMap<>(); - map.put("voucherNo", voucher_no_field.getText()); - map.put("voucherDate", voucher_date.getText()); - map.put("supplierName", supplier_name.getText()); - map.put("billAmount", total_amount_field.getText()); - JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, conn); - JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); - Utils.showAlert("Report Successfully Generated", 1); - } catch (JRException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } -} +package satyamconsignment.ui.Input.PaymentEntry.ViewAndDeletePayment; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import net.sf.jasperreports.engine.*; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; +import satyamconsignment.model.PaymentItem; +import satyamconsignment.ui.Input.CollectionEntry.CollectionEntryController; +import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController; + +public class ViewAndDeletePayment implements Initializable { + + @FXML + private TextField voucher_no_field; + + @FXML + private TableColumn bill_no_col; + + @FXML + private TableColumn bill_amt_col; + + @FXML + private TableColumn bill_date_col; + + @FXML + private TableColumn buyer_col; + + @FXML + private TableColumn amount_paid_col; + + @FXML + private TableColumn bank_col; + + @FXML + private TableColumn dd_no_col; + + @FXML + private TableColumn dd_date_col; + + @FXML + private Label display_board_label; + + @FXML + private TextField total_amount_field; + + @FXML + private Button get_details_btn; + + @FXML + private Button delete_entry_btn; + + @FXML + private TextField voucher_date; + + @FXML + private TextField supplier_name; + + @FXML + private TableColumn due_col; + + @FXML + private TableView payment_tableview; + + @FXML + private Button print_payment_btn; + + @Override + public void initialize(URL url, ResourceBundle rb) { + bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); + bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); + buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName")); + bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); + due_col.setCellValueFactory(new PropertyValueFactory<>("due")); + amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid")); + dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); + bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); + dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); + } + + @FXML + private void getDetails(ActionEvent event) { + + if (voucher_no_field.getText().isEmpty()) { + Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no."); + return; + } + try { + String sql = "select * from `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; + Connection conn = DatabaseHandler.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement(sql); + ps.setString(1, voucher_no_field.getText()); + ResultSet rs = ps.executeQuery(); + + voucher_date.setText(rs.getString("Voucher Date")); + supplier_name.setText(rs.getString("Supplier Name")); + total_amount_field.setText(rs.getString("Total Amount")); + display_board_label.setText(rs.getString("Supplier Name")); + + List list = new ArrayList<>(); + sql = "select * from `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + ps = conn.prepareStatement(sql); + ps.setString(1, voucher_no_field.getText()); + rs = ps.executeQuery(); + if (rs.isClosed()) { + Utils.showAlert("No Results found", 1); + } else { + while (rs.next()) { + PaymentItem paymentItem = PaymentItem.builder() + .billNo(rs.getString("Bill No.")) + .billAmount(rs.getString("Bill Amount")) + .billDate(rs.getString("Bill Date")) + .buyerName(rs.getString("Buyer Name")) + .due(rs.getString("due amount")) + .amountPaid(rs.getString("amount paid")) + .bank(rs.getString("bank")) + .ddNo(rs.getString("DD No.")) + .ddDate(rs.getString("DD Date")) + .build(); + + list.add(paymentItem); + } + payment_tableview.setItems(FXCollections.observableArrayList(list)); + delete_entry_btn.setDisable(false); + } + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(CollectionEntryController.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @FXML + private void deleteEntry(ActionEvent event) { + Alert alert = new Alert( + Alert.AlertType.CONFIRMATION, + "Are you sure that you want delete " + voucher_no_field.getText() + " ?", + ButtonType.YES, + ButtonType.NO, + ButtonType.CANCEL); + alert.showAndWait(); + + if (alert.getResult() != ButtonType.YES) { + return; + } + + Connection conn = DatabaseHandler.getInstance().getConnection(); + + try { + conn.setAutoCommit(false); + String sql = + "SELECT `Bill No.`,`Amount Paid` FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + PreparedStatement ps = conn.prepareStatement(sql); + ps.setString(1, voucher_no_field.getText()); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + sql = "UPDATE `Bill_Entry_Table` SET `Due`=`Due`+? WHERE `BILL NO.`=?"; + ps = conn.prepareStatement(sql); + ps.setString(1, rs.getString("Amount Paid")); + ps.setString(2, rs.getString("Bill No.")); + ps.execute(); + } + sql = "DELETE FROM `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; + ps = conn.prepareStatement(sql); + ps.setString(1, voucher_no_field.getText()); + ps.execute(); + + sql = "DELETE FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; + ps = conn.prepareStatement(sql); + ps.setString(1, voucher_no_field.getText()); + ps.execute(); + + payment_tableview.setItems(FXCollections.observableArrayList()); + + voucher_date.setText(""); + supplier_name.setText(""); + display_board_label.setText(""); + total_amount_field.setText(""); + conn.commit(); + Utils.showAlert(voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", 1); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + try { + conn.rollback(); + } catch (SQLException ex1) { + Utils.showAlert(ex1.toString()); + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex1.toString(), ex1); + } + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void printPayment(ActionEvent event) { + try { + Connection conn = DatabaseHandler.getInstance().getConnection(); + String jrxmlFileName = "/satyamconsignment/ui/Input/PaymentEntry/Payment.jrxml"; + JasperReport jasperReport = + JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFileName)); + Map map = new HashMap<>(); + map.put("voucherNo", voucher_no_field.getText()); + map.put("voucherDate", voucher_date.getText()); + map.put("supplierName", supplier_name.getText()); + map.put("billAmount", total_amount_field.getText()); + JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, conn); + JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); + Utils.showAlert("Report Successfully Generated", 1); + } catch (JRException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } +} diff --git a/src/main/java/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.java b/src/main/java/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.java index f1dabfb..aec3c86 100644 --- a/src/main/java/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.java +++ b/src/main/java/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.java @@ -25,14 +25,19 @@ public class CollectionHistory implements Initializable { @FXML private Group root; + @FXML private TableView tableView; + @FXML private TableColumn voucher_no_col; + @FXML private TableColumn voucher_date_col; + @FXML private TableColumn buyer_name_col; + @FXML private TableColumn total_amount_col; @@ -50,13 +55,15 @@ public void initialize(URL url, ResourceBundle rb) { PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { - list.add(new Record(rs.getString("Voucher No."), rs.getString("Voucher Date"), - rs.getString("Buyer Name"), rs.getString("Total Amount"))); + list.add(new Record( + rs.getString("Voucher No."), + rs.getString("Voucher Date"), + rs.getString("Buyer Name"), + rs.getString("Total Amount"))); } } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(CollectionHistory.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(CollectionHistory.class.getName()).log(Level.SEVERE, ex.toString(), ex); } tableView.setItems(list); } diff --git a/src/main/java/satyamconsignment/ui/Main/InputHistory/InputHistory.java b/src/main/java/satyamconsignment/ui/Main/InputHistory/InputHistory.java index 3e2e85c..bcb673a 100644 --- a/src/main/java/satyamconsignment/ui/Main/InputHistory/InputHistory.java +++ b/src/main/java/satyamconsignment/ui/Main/InputHistory/InputHistory.java @@ -24,20 +24,28 @@ public class InputHistory implements Initializable { @FXML private Group root; + @FXML private TableColumn supplier_name_col; + @FXML private TableColumn buyer_name_col; + @FXML private TableColumn bill_no_col; + @FXML private TableColumn bill_date_col; + @FXML private TableColumn transport_col; + @FXML private TableColumn lr_date_col; + @FXML private TableColumn bill_amount_col; + @FXML private TableView tableView; @@ -60,9 +68,13 @@ public void initialize(URL url, ResourceBundle rb) { PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { - list.add(new BillRecord(rs.getString("Supplier Name"), rs.getString("Buyer Name"), - rs.getString("Bill No."), rs.getString("Bill Date"), - rs.getString("Transport"), rs.getString("LR Date"), + list.add(new BillRecord( + rs.getString("Supplier Name"), + rs.getString("Buyer Name"), + rs.getString("Bill No."), + rs.getString("Bill Date"), + rs.getString("Transport"), + rs.getString("LR Date"), rs.getString("Bill Amount"))); } } catch (SQLException ex) { diff --git a/src/main/java/satyamconsignment/ui/Main/MainController.java b/src/main/java/satyamconsignment/ui/Main/MainController.java index c37119b..51008f7 100644 --- a/src/main/java/satyamconsignment/ui/Main/MainController.java +++ b/src/main/java/satyamconsignment/ui/Main/MainController.java @@ -1,69 +1,72 @@ -package satyamconsignment.ui.Main; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.Button; -import javafx.scene.control.MenuItem; -import javafx.scene.layout.BorderPane; -import satyamconsignment.common.ViewLoader; - -public class MainController implements Initializable { - - @FXML - private Button input_btn; - @FXML - private BorderPane root; - @FXML - private Button report_btn; - @FXML - private Button master_btn; - @FXML - private MenuItem welcome_screen; - private ViewLoader viewLoader; - - @Override - public void initialize(URL url, ResourceBundle rb) { - viewLoader = new ViewLoader(); - viewLoader.loadCenter("/satyamconsignment/ui/Main/WelcomeScreen/WelcomeScreen.fxml", root); - } - - @FXML - private void showInputScreen(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Input/Input.fxml", root); - } - - @FXML - private void showReportScreen(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Report/Report.fxml", root); - } - - @FXML - private void showMasterScreen(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Master/Master.fxml", root); - } - - @FXML - private void showWelcomeScreen(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Main/WelcomeScreen/WelcomeScreen.fxml", root); - } - - @FXML - private void showInputHistory(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Main/InputHistory/InputHistory.fxml", root); - } - - @FXML - private void showCollectionHistory(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.fxml", - root); - } - - @FXML - private void showPaymentHistory(ActionEvent event) { - viewLoader.loadCenter("/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.fxml", - root); - } -} +package satyamconsignment.ui.Main; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.MenuItem; +import javafx.scene.layout.BorderPane; +import satyamconsignment.common.ViewLoader; + +public class MainController implements Initializable { + + @FXML + private Button input_btn; + + @FXML + private BorderPane root; + + @FXML + private Button report_btn; + + @FXML + private Button master_btn; + + @FXML + private MenuItem welcome_screen; + + private ViewLoader viewLoader; + + @Override + public void initialize(URL url, ResourceBundle rb) { + viewLoader = new ViewLoader(); + viewLoader.loadCenter("/satyamconsignment/ui/Main/WelcomeScreen/WelcomeScreen.fxml", root); + } + + @FXML + private void showInputScreen(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Input/Input.fxml", root); + } + + @FXML + private void showReportScreen(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Report/Report.fxml", root); + } + + @FXML + private void showMasterScreen(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Master/Master.fxml", root); + } + + @FXML + private void showWelcomeScreen(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Main/WelcomeScreen/WelcomeScreen.fxml", root); + } + + @FXML + private void showInputHistory(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Main/InputHistory/InputHistory.fxml", root); + } + + @FXML + private void showCollectionHistory(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Main/CollectionHistory/CollectionHistory.fxml", root); + } + + @FXML + private void showPaymentHistory(ActionEvent event) { + viewLoader.loadCenter("/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.fxml", root); + } +} diff --git a/src/main/java/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.java b/src/main/java/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.java index f217ec5..04b065b 100644 --- a/src/main/java/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.java +++ b/src/main/java/satyamconsignment/ui/Main/PaymentHistory/PaymentHistory.java @@ -30,14 +30,19 @@ public class PaymentHistory implements Initializable { @FXML private Group root; + @FXML private TableView tableView; + @FXML private TableColumn voucher_no_col; + @FXML private TableColumn voucher_date_col; + @FXML private TableColumn supplier_name_col; + @FXML private TableColumn total_amount_col; @@ -55,8 +60,11 @@ public void initialize(URL url, ResourceBundle rb) { PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { - list.add(new Record(rs.getString("Voucher No."), rs.getString("Voucher Date"), - rs.getString("Supplier Name"), rs.getString("Total Amount"))); + list.add(new Record( + rs.getString("Voucher No."), + rs.getString("Voucher Date"), + rs.getString("Supplier Name"), + rs.getString("Total Amount"))); } } catch (SQLException ex) { Utils.showAlert(ex.toString()); diff --git a/src/main/java/satyamconsignment/ui/Master/Buyer/BuyerController.java b/src/main/java/satyamconsignment/ui/Master/Buyer/BuyerController.java index 288a9ac..e74f11c 100644 --- a/src/main/java/satyamconsignment/ui/Master/Buyer/BuyerController.java +++ b/src/main/java/satyamconsignment/ui/Master/Buyer/BuyerController.java @@ -30,16 +30,22 @@ public class BuyerController implements Initializable { @FXML private Button add_btn; + @FXML private ListView listView; + @FXML private Button delete_btn; + @FXML private Button refresh_btn; + @FXML private TextField add_field; + @FXML private Button rename_btn; + @FXML private TextField rename_field; @@ -53,8 +59,7 @@ public void initialize(URL url, ResourceBundle rb) { @FXML private void addMaster(ActionEvent event) { if (add_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Add field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Add field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -66,8 +71,7 @@ private void addMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } @@ -89,8 +93,7 @@ private void deleteMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } @@ -109,16 +112,14 @@ private void refreshList() { listView.getItems().setAll(buyerList); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } @FXML private void renameMaster(ActionEvent event) { if (rename_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Rename field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Rename field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -133,8 +134,7 @@ private void renameMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } } diff --git a/src/main/java/satyamconsignment/ui/Master/MasterController.java b/src/main/java/satyamconsignment/ui/Master/MasterController.java index 6ff3b67..e240035 100644 --- a/src/main/java/satyamconsignment/ui/Master/MasterController.java +++ b/src/main/java/satyamconsignment/ui/Master/MasterController.java @@ -1,54 +1,57 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package satyamconsignment.ui.Master; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.Group; -import javafx.scene.control.Button; -import satyamconsignment.common.ViewLoader; - -/** - * FXML Controller class - * - * @author ADMIN - */ -public class MasterController implements Initializable { - - @FXML - private Button supplier_master_btn; - @FXML - private Button buyer_master_btn; - @FXML - private Button transport_master_btn; - @FXML - private Group root; - - private ViewLoader viewLoader; - - @Override - public void initialize(URL url, ResourceBundle rb) { - viewLoader = new ViewLoader(); - } - - @FXML - private void showSupplierMaster(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Master/Supplier/MasterSupplier.fxml", root); - } - - @FXML - private void showBuyerMaster(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Master/Buyer/MasterBuyer.fxml", root); - } - - @FXML - private void showTransportMaster(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Master/Transport/MasterTransport.fxml", root); - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package satyamconsignment.ui.Master; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Group; +import javafx.scene.control.Button; +import satyamconsignment.common.ViewLoader; + +/** + * FXML Controller class + * + * @author ADMIN + */ +public class MasterController implements Initializable { + + @FXML + private Button supplier_master_btn; + + @FXML + private Button buyer_master_btn; + + @FXML + private Button transport_master_btn; + + @FXML + private Group root; + + private ViewLoader viewLoader; + + @Override + public void initialize(URL url, ResourceBundle rb) { + viewLoader = new ViewLoader(); + } + + @FXML + private void showSupplierMaster(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Master/Supplier/MasterSupplier.fxml", root); + } + + @FXML + private void showBuyerMaster(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Master/Buyer/MasterBuyer.fxml", root); + } + + @FXML + private void showTransportMaster(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Master/Transport/MasterTransport.fxml", root); + } +} diff --git a/src/main/java/satyamconsignment/ui/Master/Supplier/SupplierController.java b/src/main/java/satyamconsignment/ui/Master/Supplier/SupplierController.java index 25c1569..d07831b 100644 --- a/src/main/java/satyamconsignment/ui/Master/Supplier/SupplierController.java +++ b/src/main/java/satyamconsignment/ui/Master/Supplier/SupplierController.java @@ -25,16 +25,22 @@ public class SupplierController implements Initializable { @FXML private Button add_btn; + @FXML private TextField add_field; + @FXML private Button rename_btn; + @FXML private TextField rename_field; + @FXML private Button delete_btn; + @FXML private Button refresh_btn; + @FXML private ListView listView; @@ -47,8 +53,7 @@ public void initialize(URL url, ResourceBundle rb) { @FXML private void addMaster(ActionEvent event) { if (add_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Add field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Add field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -60,18 +65,15 @@ private void addMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } @FXML private void renameMaster(ActionEvent event) { if (rename_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Rename field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Rename field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -86,10 +88,8 @@ private void renameMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } @FXML @@ -110,10 +110,8 @@ private void deleteMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } @FXML @@ -131,8 +129,7 @@ private void refreshList() { listView.getItems().setAll(supplierList); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } } diff --git a/src/main/java/satyamconsignment/ui/Master/Transport/TransportController.java b/src/main/java/satyamconsignment/ui/Master/Transport/TransportController.java index 8b4b9be..b40b84c 100644 --- a/src/main/java/satyamconsignment/ui/Master/Transport/TransportController.java +++ b/src/main/java/satyamconsignment/ui/Master/Transport/TransportController.java @@ -30,16 +30,22 @@ public class TransportController implements Initializable { @FXML private Button add_btn; + @FXML private ListView listView; + @FXML private Button delete_btn; + @FXML private Button refresh_btn; + @FXML private TextField add_field; + @FXML private Button rename_btn; + @FXML private TextField rename_field; @@ -53,8 +59,7 @@ public void initialize(URL url, ResourceBundle rb) { @FXML private void addMaster(ActionEvent event) { if (add_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Add field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Add field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -66,10 +71,8 @@ private void addMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } @FXML @@ -90,10 +93,8 @@ private void deleteMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } @FXML @@ -111,16 +112,14 @@ private void refreshList() { listView.getItems().setAll(buyerList); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } @FXML private void renameMaster(ActionEvent event) { if (rename_field.getText().compareTo("") == 0) { - Utils.showAlert( - "Rename field is left blank. Please ensure to fill up the field properly."); + Utils.showAlert("Rename field is left blank. Please ensure to fill up the field properly."); return; } try { @@ -135,9 +134,7 @@ private void renameMaster(ActionEvent event) { refreshList(); } catch (SQLException ex) { Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); + Logger.getLogger(SupplierController.class.getName()).log(Level.SEVERE, ex.toString(), ex); } - } } diff --git a/src/main/java/satyamconsignment/ui/Report/BuyerLedger/BuyerLedgerController.java b/src/main/java/satyamconsignment/ui/Report/BuyerLedger/BuyerLedgerController.java index e0f2e65..f86c8b7 100644 --- a/src/main/java/satyamconsignment/ui/Report/BuyerLedger/BuyerLedgerController.java +++ b/src/main/java/satyamconsignment/ui/Report/BuyerLedger/BuyerLedgerController.java @@ -1,98 +1,101 @@ -package satyamconsignment.ui.Report.BuyerLedger; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.Button; -import javafx.scene.control.ComboBox; -import javafx.scene.control.RadioButton; -import javafx.scene.control.ToggleGroup; -import net.sf.jasperreports.engine.*; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; - -public class BuyerLedgerController implements Initializable { - DatabaseHandler databaseHandler; - Connection conn; - PreparedStatement ps; - ResultSet rs; - ObservableList buyerList; - - @FXML - private RadioButton buyer_ledger_radio; - @FXML - private ToggleGroup choice; - @FXML - private RadioButton agewise_outstanding_radio; - @FXML - private Button generate_pdf_btn; - @FXML - private ComboBox buyer_name_combo; - @FXML - private Button launch_pdf_btn; - - @Override - public void initialize(URL url, ResourceBundle rb) { - try { - - databaseHandler = DatabaseHandler.getInstance(); - conn = databaseHandler.getConnection(); - ps = conn.prepareStatement( - "select * from Buyer_Master_Table order by name collate nocase"); - rs = ps.executeQuery(); - buyerList = FXCollections.observableArrayList(); - while (rs.next()) { - buyerList.add(rs.getString("name")); - } - buyer_name_combo.setItems(buyerList); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(BuyerLedgerController.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @FXML - private void generatePDF(ActionEvent event) { - String jrxmlFileName; - if (agewise_outstanding_radio.isSelected()) { - jrxmlFileName = "BuyerLedgerAge.jrxml"; - } else { - jrxmlFileName = "BuyerLedger.jrxml"; - } - String jrxmlFilePath = "/satyamconsignment/ui/Report/BuyerLedger/" + jrxmlFileName; - - Map map = new HashMap<>(); - map.put("buyerName", buyer_name_combo.getSelectionModel().getSelectedItem()); - - try { - JasperReport jasperReport = JasperCompileManager - .compileReport(getClass().getResourceAsStream(jrxmlFilePath)); - JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, conn); - JasperExportManager.exportReportToPdfFile(jasperPrint, Constants.REPORT_FILE_NAME); - Utils.showAlert("Report Successfully Generated", 1); - } catch (JRException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(BuyerLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), - ex); - } - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } - - @FXML - private void launchPdf(ActionEvent event) { - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } -} +package satyamconsignment.ui.Report.BuyerLedger; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.RadioButton; +import javafx.scene.control.ToggleGroup; +import net.sf.jasperreports.engine.*; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; + +public class BuyerLedgerController implements Initializable { + DatabaseHandler databaseHandler; + Connection conn; + PreparedStatement ps; + ResultSet rs; + ObservableList buyerList; + + @FXML + private RadioButton buyer_ledger_radio; + + @FXML + private ToggleGroup choice; + + @FXML + private RadioButton agewise_outstanding_radio; + + @FXML + private Button generate_pdf_btn; + + @FXML + private ComboBox buyer_name_combo; + + @FXML + private Button launch_pdf_btn; + + @Override + public void initialize(URL url, ResourceBundle rb) { + try { + + databaseHandler = DatabaseHandler.getInstance(); + conn = databaseHandler.getConnection(); + ps = conn.prepareStatement("select * from Buyer_Master_Table order by name collate nocase"); + rs = ps.executeQuery(); + buyerList = FXCollections.observableArrayList(); + while (rs.next()) { + buyerList.add(rs.getString("name")); + } + buyer_name_combo.setItems(buyerList); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(BuyerLedgerController.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @FXML + private void generatePDF(ActionEvent event) { + String jrxmlFileName; + if (agewise_outstanding_radio.isSelected()) { + jrxmlFileName = "BuyerLedgerAge.jrxml"; + } else { + jrxmlFileName = "BuyerLedger.jrxml"; + } + String jrxmlFilePath = "/satyamconsignment/ui/Report/BuyerLedger/" + jrxmlFileName; + + Map map = new HashMap<>(); + map.put("buyerName", buyer_name_combo.getSelectionModel().getSelectedItem()); + + try { + JasperReport jasperReport = + JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFilePath)); + JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, conn); + JasperExportManager.exportReportToPdfFile(jasperPrint, Constants.REPORT_FILE_NAME); + Utils.showAlert("Report Successfully Generated", 1); + } catch (JRException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(BuyerLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } + + @FXML + private void launchPdf(ActionEvent event) { + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } +} diff --git a/src/main/java/satyamconsignment/ui/Report/ReportController.java b/src/main/java/satyamconsignment/ui/Report/ReportController.java index ed505fd..f8975cb 100644 --- a/src/main/java/satyamconsignment/ui/Report/ReportController.java +++ b/src/main/java/satyamconsignment/ui/Report/ReportController.java @@ -1,46 +1,47 @@ -package satyamconsignment.ui.Report; - -import java.net.URL; -import java.util.ResourceBundle; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.Group; -import javafx.scene.control.Button; -import satyamconsignment.common.ViewLoader; - -public class ReportController implements Initializable { - - @FXML - private Button supplier_ledger_btn; - @FXML - private Button buyer_ledger_brn; - @FXML - private Button transport_ledger_btn; - @FXML - private Group root; - - private ViewLoader viewLoader; - - @Override - public void initialize(URL url, ResourceBundle rb) { - viewLoader = new ViewLoader(); - } - - @FXML - private void showSupplierLedger(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Report/SupplierLedger/SupplierLedger.fxml", - root); - } - - @FXML - private void showBuyerLedger(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Report/BuyerLedger/BuyerLedger.fxml", root); - } - - @FXML - private void showTransportLedger(ActionEvent event) { - viewLoader.loadRoot("/satyamconsignment/ui/Report/TransportLedger/TransportLedger.fxml", - root); - } -} +package satyamconsignment.ui.Report; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Group; +import javafx.scene.control.Button; +import satyamconsignment.common.ViewLoader; + +public class ReportController implements Initializable { + + @FXML + private Button supplier_ledger_btn; + + @FXML + private Button buyer_ledger_brn; + + @FXML + private Button transport_ledger_btn; + + @FXML + private Group root; + + private ViewLoader viewLoader; + + @Override + public void initialize(URL url, ResourceBundle rb) { + viewLoader = new ViewLoader(); + } + + @FXML + private void showSupplierLedger(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Report/SupplierLedger/SupplierLedger.fxml", root); + } + + @FXML + private void showBuyerLedger(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Report/BuyerLedger/BuyerLedger.fxml", root); + } + + @FXML + private void showTransportLedger(ActionEvent event) { + viewLoader.loadRoot("/satyamconsignment/ui/Report/TransportLedger/TransportLedger.fxml", root); + } +} diff --git a/src/main/java/satyamconsignment/ui/Report/SupplierLedger/SupplierLedgerController.java b/src/main/java/satyamconsignment/ui/Report/SupplierLedger/SupplierLedgerController.java index 58d7963..f51e02b 100644 --- a/src/main/java/satyamconsignment/ui/Report/SupplierLedger/SupplierLedgerController.java +++ b/src/main/java/satyamconsignment/ui/Report/SupplierLedger/SupplierLedgerController.java @@ -1,98 +1,100 @@ -package satyamconsignment.ui.Report.SupplierLedger; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.Button; -import javafx.scene.control.ComboBox; -import javafx.scene.control.RadioButton; -import javafx.scene.control.ToggleGroup; -import net.sf.jasperreports.engine.*; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; - -public class SupplierLedgerController implements Initializable { - DatabaseHandler databaseHandler; - Connection conn; - PreparedStatement ps; - ResultSet rs; - ObservableList supplierList; - - @FXML - private ComboBox supplier_name_combo; - @FXML - private ToggleGroup choice; - @FXML - private RadioButton supplier_ledger_radio; - @FXML - private RadioButton agewise_outstanding_radio; - @FXML - private Button generate_pdf_btn; - @FXML - private Button launch_pdf_btn; - - @Override - public void initialize(URL url, ResourceBundle rb) { - try { - databaseHandler = DatabaseHandler.getInstance(); - conn = databaseHandler.getConnection(); - ps = conn.prepareStatement( - "select * from Supplier_Master_Table order by name collate nocase"); - rs = ps.executeQuery(); - supplierList = FXCollections.observableArrayList(); - while (rs.next()) { - supplierList.add(rs.getString("name")); - } - supplier_name_combo.setItems(supplierList); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierLedgerController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - } - - @FXML - private void generatePDF(ActionEvent event) { - String jrxmlFileName; - if (agewise_outstanding_radio.isSelected()) { - jrxmlFileName = "SupplierLedgerAge.jrxml"; - } else { - jrxmlFileName = "SupplierLedger.jrxml"; - } - String jrxmlFilePath = "/satyamconsignment/ui/Report/SupplierLedger/" + jrxmlFileName; - Map map = new HashMap<>(); - map.put("supplierName", supplier_name_combo.getSelectionModel().getSelectedItem()); - - try { - - JasperReport jasperReport = JasperCompileManager - .compileReport(getClass().getResourceAsStream(jrxmlFilePath)); - JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, conn); - JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); - Utils.showAlert("Report Successfully Generated", 1); - } catch (JRException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(SupplierLedgerController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } - - @FXML - private void launchPdf(ActionEvent event) { - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } -} +package satyamconsignment.ui.Report.SupplierLedger; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.RadioButton; +import javafx.scene.control.ToggleGroup; +import net.sf.jasperreports.engine.*; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; + +public class SupplierLedgerController implements Initializable { + DatabaseHandler databaseHandler; + Connection conn; + PreparedStatement ps; + ResultSet rs; + ObservableList supplierList; + + @FXML + private ComboBox supplier_name_combo; + + @FXML + private ToggleGroup choice; + + @FXML + private RadioButton supplier_ledger_radio; + + @FXML + private RadioButton agewise_outstanding_radio; + + @FXML + private Button generate_pdf_btn; + + @FXML + private Button launch_pdf_btn; + + @Override + public void initialize(URL url, ResourceBundle rb) { + try { + databaseHandler = DatabaseHandler.getInstance(); + conn = databaseHandler.getConnection(); + ps = conn.prepareStatement("select * from Supplier_Master_Table order by name collate nocase"); + rs = ps.executeQuery(); + supplierList = FXCollections.observableArrayList(); + while (rs.next()) { + supplierList.add(rs.getString("name")); + } + supplier_name_combo.setItems(supplierList); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(SupplierLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void generatePDF(ActionEvent event) { + String jrxmlFileName; + if (agewise_outstanding_radio.isSelected()) { + jrxmlFileName = "SupplierLedgerAge.jrxml"; + } else { + jrxmlFileName = "SupplierLedger.jrxml"; + } + String jrxmlFilePath = "/satyamconsignment/ui/Report/SupplierLedger/" + jrxmlFileName; + Map map = new HashMap<>(); + map.put("supplierName", supplier_name_combo.getSelectionModel().getSelectedItem()); + + try { + + JasperReport jasperReport = + JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFilePath)); + JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, conn); + JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); + Utils.showAlert("Report Successfully Generated", 1); + } catch (JRException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(SupplierLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } + + @FXML + private void launchPdf(ActionEvent event) { + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } +} diff --git a/src/main/java/satyamconsignment/ui/Report/TransportLedger/TransportLedgerController.java b/src/main/java/satyamconsignment/ui/Report/TransportLedger/TransportLedgerController.java index db6d606..0c61588 100644 --- a/src/main/java/satyamconsignment/ui/Report/TransportLedger/TransportLedgerController.java +++ b/src/main/java/satyamconsignment/ui/Report/TransportLedger/TransportLedgerController.java @@ -1,107 +1,109 @@ -package satyamconsignment.ui.Report.TransportLedger; - -import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.DatePicker; -import net.sf.jasperreports.engine.*; -import satyamconsignment.common.Constants; -import satyamconsignment.common.DatabaseHandler; -import satyamconsignment.common.Utils; - -public class TransportLedgerController implements Initializable { - DatabaseHandler databaseHandler; - Connection conn; - PreparedStatement ps; - ResultSet rs; - ObservableList transportList; - - @FXML - private CheckBox all_time_checkbox; - @FXML - private ComboBox transport_name_combo; - @FXML - private DatePicker from_date; - @FXML - private DatePicker to_date; - @FXML - private Button generate_pdf_report_btn; - @FXML - private Button launch_report_btn; - - @Override - public void initialize(URL url, ResourceBundle rb) { - try { - databaseHandler = DatabaseHandler.getInstance(); - conn = databaseHandler.getConnection(); - ps = conn.prepareStatement( - "select * from Transport_Master_Table order by name collate nocase"); - rs = ps.executeQuery(); - transportList = FXCollections.observableArrayList(); - while (rs.next()) { - transportList.add(rs.getString("name")); - } - transport_name_combo.setItems(transportList); - } catch (SQLException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(TransportLedgerController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - } - - @FXML - private void generatePDF(ActionEvent event) { - String jrxmlFileName = "TransportLedger.jrxml"; - String jrxmlFilePath = "/satyamconsignment/ui/Report/TransportLedger/" + jrxmlFileName; - - Map map = new HashMap<>(); - map.put("transportName", transport_name_combo.getSelectionModel().getSelectedItem()); - map.put("fromDate", "01-01-2000"); - map.put("toDate", "31-12-2100"); - - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - - if (!all_time_checkbox.isSelected()) { - if (from_date.getValue() == null || to_date.getValue() == null) { - Utils.showAlert("Select dates properly"); - return; - } - map.put("fromDate", from_date.getValue().format(formatter)); - map.put("toDate", to_date.getValue().format(formatter)); - } - - try { - JasperReport jasperReport = JasperCompileManager - .compileReport(getClass().getResourceAsStream(jrxmlFilePath)); - JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, conn); - JasperExportManager.exportReportToPdfFile(jasperPrint, Constants.REPORT_FILE_NAME); - Utils.showAlert("Report Successfully Generated", 1); - } catch (JRException ex) { - Utils.showAlert(ex.toString()); - Logger.getLogger(TransportLedgerController.class.getName()).log(Level.SEVERE, - ex.toString(), ex); - } - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } - - @FXML - private void launchPdf(ActionEvent event) { - Utils.launchPdf(Constants.REPORT_FILE_NAME); - } -} +package satyamconsignment.ui.Report.TransportLedger; + +import java.net.URL; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.DatePicker; +import net.sf.jasperreports.engine.*; +import satyamconsignment.common.Constants; +import satyamconsignment.common.DatabaseHandler; +import satyamconsignment.common.Utils; + +public class TransportLedgerController implements Initializable { + DatabaseHandler databaseHandler; + Connection conn; + PreparedStatement ps; + ResultSet rs; + ObservableList transportList; + + @FXML + private CheckBox all_time_checkbox; + + @FXML + private ComboBox transport_name_combo; + + @FXML + private DatePicker from_date; + + @FXML + private DatePicker to_date; + + @FXML + private Button generate_pdf_report_btn; + + @FXML + private Button launch_report_btn; + + @Override + public void initialize(URL url, ResourceBundle rb) { + try { + databaseHandler = DatabaseHandler.getInstance(); + conn = databaseHandler.getConnection(); + ps = conn.prepareStatement("select * from Transport_Master_Table order by name collate nocase"); + rs = ps.executeQuery(); + transportList = FXCollections.observableArrayList(); + while (rs.next()) { + transportList.add(rs.getString("name")); + } + transport_name_combo.setItems(transportList); + } catch (SQLException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(TransportLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + } + + @FXML + private void generatePDF(ActionEvent event) { + String jrxmlFileName = "TransportLedger.jrxml"; + String jrxmlFilePath = "/satyamconsignment/ui/Report/TransportLedger/" + jrxmlFileName; + + Map map = new HashMap<>(); + map.put("transportName", transport_name_combo.getSelectionModel().getSelectedItem()); + map.put("fromDate", "01-01-2000"); + map.put("toDate", "31-12-2100"); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + + if (!all_time_checkbox.isSelected()) { + if (from_date.getValue() == null || to_date.getValue() == null) { + Utils.showAlert("Select dates properly"); + return; + } + map.put("fromDate", from_date.getValue().format(formatter)); + map.put("toDate", to_date.getValue().format(formatter)); + } + + try { + JasperReport jasperReport = + JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFilePath)); + JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, conn); + JasperExportManager.exportReportToPdfFile(jasperPrint, Constants.REPORT_FILE_NAME); + Utils.showAlert("Report Successfully Generated", 1); + } catch (JRException ex) { + Utils.showAlert(ex.toString()); + Logger.getLogger(TransportLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex); + } + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } + + @FXML + private void launchPdf(ActionEvent event) { + Utils.launchPdf(Constants.REPORT_FILE_NAME); + } +} diff --git a/src/test/java/functional/BillEntryTest.java b/src/test/java/functional/BillEntryTest.java index d5a7201..b148884 100644 --- a/src/test/java/functional/BillEntryTest.java +++ b/src/test/java/functional/BillEntryTest.java @@ -1,23 +1,19 @@ package functional; +import static org.testfx.util.WaitForAsyncUtils.waitForFxEvents; + import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import org.junit.jupiter.api.Test; import org.testfx.framework.junit5.ApplicationTest; -import org.testfx.matcher.base.NodeMatchers; - -import static org.testfx.api.FxAssert.verifyThat; -import static org.testfx.util.WaitForAsyncUtils.waitForFxEvents; public class BillEntryTest extends ApplicationTest { @Override public void start(Stage stage) throws Exception { - FXMLLoader loader = new FXMLLoader( - getClass().getResource("/satyamconsignment/ui/Main/Main.fxml") - ); + FXMLLoader loader = new FXMLLoader(getClass().getResource("/satyamconsignment/ui/Main/Main.fxml")); Parent root = loader.load(); stage.setScene(new Scene(root)); @@ -28,27 +24,25 @@ public void start(Stage stage) throws Exception { @Test void testIfLoadedProperly() { waitForFxEvents(); -// clickOn("#input_btn"); -// -// verifyThat("#bill_entry_btn", NodeMatchers.isVisible()); -// clickOn("#bill_entry_btn"); -// -// verifyThat("#TabButtonAdd", NodeMatchers.isVisible()); -// clickOn("#TabButtonAdd"); -// -// verifyThat("#supplier_field", NodeMatchers.isVisible()); -//// clickOn("#supplier_field"); -// -// interact(() -> { -// lookup("#supplier_field").queryTextInputControl().setText("ajanta"); -// }); -// -// -// verifyThat("#buyer_name_field", NodeMatchers.isVisible()); -// clickOn("#buyer_name_field"); -// -// write("hello"); + // clickOn("#input_btn"); + // + // verifyThat("#bill_entry_btn", NodeMatchers.isVisible()); + // clickOn("#bill_entry_btn"); + // + // verifyThat("#TabButtonAdd", NodeMatchers.isVisible()); + // clickOn("#TabButtonAdd"); + // + // verifyThat("#supplier_field", NodeMatchers.isVisible()); + //// clickOn("#supplier_field"); + // + // interact(() -> { + // lookup("#supplier_field").queryTextInputControl().setText("ajanta"); + // }); + // + // + // verifyThat("#buyer_name_field", NodeMatchers.isVisible()); + // clickOn("#buyer_name_field"); + // + // write("hello"); } - - }