Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design patters corrections #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
63 changes: 57 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@

<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>com.rafsan.inventory.MainApp</mainClass>
</configuration>
</plugin>

<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-plugin</artifactId>
<version>0.0.14</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -43,7 +57,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<version>3.1.0</version>
<executions>
<execution>
<id>unpack-dependencies</id>
Expand Down Expand Up @@ -83,15 +97,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8.1</version> <!-- Actualización de la versión -->
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>9</source> <!-- Versión de origen de Java -->
<target>9</target> <!-- Versión de destino de Java -->
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -108,7 +123,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
<version>8.0.30</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand All @@ -133,7 +148,43 @@
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.11</version>
<version>5.5.13.3</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>19</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>19</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>19</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>19</version>
</dependency>
</dependencies>
</project>
15 changes: 15 additions & 0 deletions src/main/java/com/rafsan/inventory/AppState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.rafsan.inventory;

import com.rafsan.inventory.entity.Employee;

public class AppState {
private Employee employee;

public void setEmployee(Employee employee) {
this.employee = employee;
}

public Employee getEmployee() {
return employee;
}
}
13 changes: 11 additions & 2 deletions src/main/java/com/rafsan/inventory/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.rafsan.inventory;

import com.rafsan.inventory.interfaces.Controller;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -14,12 +15,19 @@

public class MainApp extends Application {

private AppState appState = new AppState();

private double xOffset = 0;
private double yOffset = 0;

@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Login.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Login.fxml"));

Controller controller = loader.getController();
controller.setAppState(appState);

Parent root = loader.load();
root.setOnMousePressed((MouseEvent event) -> {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
Expand All @@ -28,6 +36,7 @@ public void start(Stage stage) throws Exception {
stage.setX(event.getScreenX() - xOffset);
stage.setY(event.getScreenY() - yOffset);
});

Scene scene = new Scene(root);
stage.setTitle("Inventory:: Version 1.0");
stage.getIcons().add(new Image("/images/logo.png"));
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/rafsan/inventory/adapters/ItemAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.rafsan.inventory.adapters;

import com.rafsan.inventory.entity.Item;
import com.rafsan.inventory.entity.ProductBase;

public class ItemAdapter extends ProductBase {
private Item item;

public ItemAdapter(Item item) {
this.item = item;
}

@Override
public String getProductName() {
return item.getItemName();
}

@Override
public double getPrice() {
return item.getUnitPrice();
}

@Override
public double getQuantity() {
return this.getQuantity();
}
}
68 changes: 68 additions & 0 deletions src/main/java/com/rafsan/inventory/builders/InvoiceBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.rafsan.inventory.builders;

import com.rafsan.inventory.entity.Employee;
import com.rafsan.inventory.entity.Invoice;
import com.rafsan.inventory.interfaces.Builder;

public class InvoiceBuilder implements Builder<Invoice> {

private String id;
private Employee employee;
private double total;
private double vat;
private double discount;
private double payable;
private double paid;
private double returned;
private String date;

public InvoiceBuilder setId(String id) {
this.id = id;
return this;
}

public InvoiceBuilder setEmployee(Employee employee) {
this.employee = employee;
return this;
}

public InvoiceBuilder setTotal(double total) {
this.total = total;
return this;
}

public InvoiceBuilder setVat(double vat) {
this.vat = vat;
return this;
}

public InvoiceBuilder setDiscount(double discount) {
this.discount = discount;
return this;
}

public InvoiceBuilder setPayable(double payable) {
this.payable = payable;
return this;
}

public InvoiceBuilder setPaid(double paid) {
this.paid = paid;
return this;
}

public InvoiceBuilder setReturned(double returned) {
this.returned = returned;
return this;
}

public InvoiceBuilder setDate(String date) {
this.date = date;
return this;
}

@Override
public Invoice build() {
return new Invoice(id, employee, total, vat, discount, payable, paid, returned, date);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rafsan.inventory.controller.admin;

import com.rafsan.inventory.AppState;
import com.rafsan.inventory.entity.Invoice;
import com.rafsan.inventory.entity.Product;
import com.rafsan.inventory.model.InvoiceModel;
Expand Down Expand Up @@ -33,6 +34,8 @@

public class AdminController implements Initializable {

private AppState appState;

private double xOffset = 0;
private double yOffset = 0;

Expand Down Expand Up @@ -136,6 +139,11 @@ private void loadStockChart(){
stockChart.getData().addAll(lists);
}


public void setAppState(AppState appState) {
this.appState = appState;
}

@FXML
public void productAction(ActionEvent event) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.rafsan.inventory.controller.login;

import com.rafsan.inventory.AppState;
import com.rafsan.inventory.interfaces.Controller;
import com.rafsan.inventory.model.EmployeeModel;
import java.net.URL;
import java.util.ResourceBundle;
Expand All @@ -21,7 +23,9 @@
import javafx.stage.Stage;
import org.apache.commons.codec.digest.DigestUtils;

public class LoginController implements Initializable {
public class LoginController implements Initializable, Controller {

private AppState appState;

@FXML
private TextField usernameField, passwordField;
Expand All @@ -35,6 +39,10 @@ public void initialize(URL url, ResourceBundle rb) {
enterPressed();
}

public void setAppState(AppState appState) {
this.appState = appState;
}

private void enterPressed() {

usernameField.setOnKeyPressed((KeyEvent ke) -> {
Expand Down Expand Up @@ -100,7 +108,12 @@ private void authenticate(Event event) throws Exception {

private void windows(String path, String title) throws Exception {

Parent root = FXMLLoader.load(getClass().getResource(path));
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));

Controller controller = loader.getController();
controller.setAppState(appState);

Parent root = loader.load();
Stage stage = new Stage();
Scene scene = new Scene(root);
stage.setTitle(title);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rafsan.inventory.controller.pos;

import com.rafsan.inventory.AppState;
import com.rafsan.inventory.entity.Item;
import com.rafsan.inventory.entity.Payment;
import com.rafsan.inventory.entity.Product;
Expand Down Expand Up @@ -29,12 +30,15 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.scene.Node;

import com.rafsan.inventory.interfaces.Controller;
import com.rafsan.inventory.interfaces.ProductInterface;
import static com.rafsan.inventory.interfaces.ProductInterface.PRODUCTLIST;
import javafx.scene.input.MouseEvent;
import javafx.stage.StageStyle;

public class PosController implements Initializable, ProductInterface {
public class PosController implements Initializable, ProductInterface, Controller {

private AppState appState;

@FXML
private TableView<Product> productTableView;
Expand Down Expand Up @@ -116,6 +120,10 @@ private void filterData() {
});
}

public void setAppState(AppState appState) {
this.appState = appState;
}

private void loadData() {
if (!PRODUCTLIST.isEmpty()) {
PRODUCTLIST.clear();
Expand Down
Loading