Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 24 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,36 @@ dependencies {

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'
Expand All @@ -57,32 +80,10 @@ run {
jvmArgs += ['--add-exports=javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED']
}

jar {
manifest {
attributes(
'Manifest-Version': 1.0,
'Main-Class': mainClassName,
"Class-Path": configurations.runtimeClasspath.collect { "lib/" + it.getName() }.join(' ')
)
}
}

shadowJar {
archiveClassifier.set("")
}

def dependencyDirectory = layout.buildDirectory.dir("libs/lib")

tasks.register('copyDatabase', Copy) {
from('data') {
include 'database.db'
}
into "${layout.buildDirectory.get()}/libs"
doLast {
println "Copied database.db to build directory"
}
}

tasks.register('copyScripts', Copy) {
from('scripts') {
include 'start.sh'
Expand All @@ -94,35 +95,8 @@ tasks.register('copyScripts', Copy) {
}
}


tasks.register('copyRuntimeDeps', Copy) {
from(configurations.runtimeClasspath)
into(dependencyDirectory)
doLast {
println "Copied runtime dependencies"
}
}

tasks.register('copyDeps', Copy) {
from(configurations.compileClasspath)
into(dependencyDirectory)
doLast {
println "Copied compile-time dependencies"
}
}

tasks.named('jar') {
dependsOn (
tasks.named('copyScripts'),
tasks.named('copyDatabase'),
tasks.named('copyDeps'),
tasks.named('copyRuntimeDeps')
)
}

tasks.named('shadowJar') {
dependsOn (
tasks.named('copyScripts'),
tasks.named('copyDatabase'),
tasks.named('copyScripts')
)
}
4 changes: 2 additions & 2 deletions scripts/start.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set JAVA_HOME="C:\Program Files\Java\jdk-11.0.16\lib"
set PATH="C:\Program Files\Java\jdk-11.0.16\bin"
set JAVA_HOME="C:\Program Files\Java\jdk-17\lib"
set PATH="C:\Program Files\Java\jdk-17\bin"

java --module-path "C:\Users\rrajd\openjfx-19_windows-x64_bin-sdk\javafx-sdk-19\lib" ^
--add-modules javafx.controls,javafx.base,javafx.graphics,javafx.fxml ^
Expand Down
1 change: 1 addition & 0 deletions src/main/java/satyamconsignment/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class Constants {
public static final String REPORT_FILE_NAME = "report.pdf";
public static final String DATE_TIME_FORMAT = "dd-MM-yyyy";
public static final String DATABASE_FILE_NAME = "database.db";
}
41 changes: 40 additions & 1 deletion src/main/java/satyamconsignment/common/DatabaseHandler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
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;

Expand All @@ -11,10 +15,45 @@ 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:database.db");
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<TabPane layoutX="41.0" layoutY="87.0" prefHeight="633.0" prefWidth="717.0"
tabClosingPolicy="UNAVAILABLE" style="-fx-tab-min-width: 120px; -fx-tab-max-width: 120px;">
<tabs>
<Tab text="Add" closable="false">
<Tab fx:id="TabButtonAdd" text="Add" closable="false">
<content>
<fx:include fx:id="AddBill" source="AddBill/AddBill.fxml"/>
</content>
Expand Down
76 changes: 76 additions & 0 deletions src/main/resources/sql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CREATE TABLE IF NOT EXISTS `Transport_Master_Table`
(
`name` TEXT NOT NULL,
PRIMARY KEY (`name`)
);
CREATE TABLE IF NOT EXISTS `Supplier_Master_Table`
(
`Name` TEXT NOT NULL,
PRIMARY KEY (`Name`)
);
CREATE TABLE IF NOT EXISTS "Payment_Entry_Table"
(
`Voucher No.` TEXT NOT NULL,
`Voucher Date` TEXT NOT NULL,
`Supplier Name` TEXT NOT NULL,
`Total Amount` TEXT NOT NULL,
PRIMARY KEY (`Voucher No.`)
);
CREATE TABLE IF NOT EXISTS "Payment_Entry_Extended_Table"
(
`Voucher No.` TEXT NOT NULL,
`Buyer Name` TEXT NOT NULL,
`Bill No.` TEXT NOT NULL,
`Bill Date` TEXT NOT NULL,
`Bill Amount` TEXT NOT NULL,
`Due Amount` TEXT NOT NULL,
`Amount Paid` TEXT NOT NULL,
`Bank` TEXT NOT NULL,
`DD No.` TEXT NOT NULL,
`DD Date` TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS `LR_Table`
(
`Bill No.` TEXT NOT NULL,
`LR No.` TEXT NOT NULL,
`PM` TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "Collection_Entry_Table"
(
`Voucher No.` TEXT NOT NULL,
`Voucher Date` TEXT NOT NULL,
`Buyer Name` TEXT NOT NULL,
`Total Amount` TEXT NOT NULL,
PRIMARY KEY (`Voucher No.`)
);
CREATE TABLE IF NOT EXISTS "Collection_Entry_Extended_Table"
(
`Voucher No.` TEXT NOT NULL,
`Supplier Name` TEXT NOT NULL,
`Bill No.` TEXT NOT NULL,
`Bill Date` TEXT NOT NULL,
`Bill Amount` TEXT NOT NULL,
`Collection Due` TEXT NOT NULL,
`Amount Collected` TEXT NOT NULL,
`Bank` TEXT NOT NULL,
`DD No.` TEXT NOT NULL,
`DD Date` TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS `Buyer_Master_Table`
(
`Name` TEXT NOT NULL,
PRIMARY KEY (`Name`)
);
CREATE TABLE IF NOT EXISTS "Bill_Entry_Table"
(
`Supplier Name` TEXT NOT NULL,
`Buyer Name` TEXT NOT NULL,
`Bill No.` TEXT NOT NULL,
`Bill Date` TEXT NOT NULL,
`Transport` TEXT NOT NULL,
`LR Date` TEXT NOT NULL,
`Bill Amount` TEXT NOT NULL,
`Collection Due` TEXT NOT NULL,
`Due` TEXT NOT NULL,
PRIMARY KEY (`Bill No.`)
);
54 changes: 54 additions & 0 deletions src/test/java/functional/BillEntryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package functional;

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")
);

Parent root = loader.load();
stage.setScene(new Scene(root));
stage.setMaximized(true);
stage.show();
}

@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");
}


}