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
26 changes: 26 additions & 0 deletions src/main/java/satyamconsignment/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

public class Utils {

Expand Down Expand Up @@ -80,4 +84,26 @@ public static String formatDate(String dateString) {
}
}
}

public static LocalDate parseDate(String dateString) {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
return LocalDate.parse(dateString, inputFormatter);
}

public static void generatePdf(String jrxmlFileName, Map<String, Object> payload, List<?> dataRows)
throws JRException {
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(dataRows);

String jrxmlFilePath = "/jrxml/" + jrxmlFileName;

try {
JasperReport jasperReport =
JasperCompileManager.compileReport(Utils.class.getResourceAsStream(jrxmlFilePath));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, payload, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, Constants.REPORT_FILE_NAME);
} catch (JRException ex) {
Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, ex.toString(), ex);
throw ex;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
import satyamconsignment.entity.BillEntity;
import satyamconsignment.entity.LREntity;
import satyamconsignment.model.LR;
import satyamconsignment.repository.BillRepository;
import satyamconsignment.repository.BuyerRepository;
import satyamconsignment.repository.SupplierRepository;
import satyamconsignment.repository.TransportRepository;
import satyamconsignment.service.BillService;
import satyamconsignment.service.BuyerService;
import satyamconsignment.service.SupplierService;
import satyamconsignment.service.TransportService;
import satyamconsignment.repository.*;
import satyamconsignment.service.*;

public class AddBillController implements Initializable {

Expand Down Expand Up @@ -89,8 +83,10 @@ public class AddBillController implements Initializable {
public void initialize(URL url, ResourceBundle rb) {
try {
billService = new BillService(new BillRepository());
SupplierService supplierService = new SupplierService(new SupplierRepository());
BuyerService buyerService = new BuyerService(new BuyerRepository());
SupplierService supplierService =
new SupplierService(new SupplierRepository(), new PaymentService(new PaymentRepository()));
BuyerService buyerService =
new BuyerService(new BuyerRepository(), new CollectionService(new CollectionRepository()));
TransportService transportService = new TransportService(new TransportRepository());

TextFields.bindAutoCompletion(supplier_field, supplierService.getAllSuppliers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class AddCollectionController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle rb) {
billService = new BillService(new BillRepository());
buyerService = new BuyerService(new BuyerRepository());
buyerService = new BuyerService(new BuyerRepository(), new CollectionService(new CollectionRepository()));
collectionService = new CollectionService(new CollectionRepository());

collectionItemList = new ArrayList<>();
Expand Down Expand Up @@ -143,7 +143,7 @@ private void fillBuyerNameCombo() {
@FXML
private void fillBillNoCombo() {
try {
billNoComboList = collectionService.fetchPendingBillsForBuyer(buyer_name.getValue());
billNoComboList = collectionService.fetchPendingBillNosForBuyer(buyer_name.getValue());
bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList));
} catch (SQLException ex) {
Utils.showAlert(ex.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
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;
Expand All @@ -18,7 +15,6 @@
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.entity.CollectionEntity;
import satyamconsignment.model.CollectionItem;
Expand Down Expand Up @@ -173,20 +169,10 @@ private void deleteEntry(ActionEvent event) {
@FXML
private void printCollection(ActionEvent event) {
try {
Connection connection = DatabaseHandler.getInstance().getConnection();
String jrxmlFileName = "/jrxml/Collection.jrxml";
JasperReport jasperReport =
JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFileName));
Map<String, Object> 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);
collectionService.generatePdf(voucher_no_field.getText());
Utils.launchPdf(Constants.REPORT_FILE_NAME);
Utils.showAlert("Report Successfully Generated", 1);
} catch (IOException | JRException ex) {
} catch (JRException | SQLException | IOException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(ViewDeleteCollectionController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class AddPaymentController implements Initializable {
public void initialize(URL url, ResourceBundle rb) {
billService = new BillService(new BillRepository());
paymentService = new PaymentService(new PaymentRepository());
supplierService = new SupplierService(new SupplierRepository());
supplierService = new SupplierService(new SupplierRepository(), new PaymentService(new PaymentRepository()));

paymentItems = new ArrayList<>();
supplierNameComboList = new ArrayList<>();
Expand Down Expand Up @@ -359,7 +359,7 @@ private void fillSupplierCombo() {
@FXML
private void fillBillNoCombo(ActionEvent ignoredEvent) {
try {
billNoComboList = paymentService.fetchPendingBillsForSupplier(supplier_name_combo.getValue());
billNoComboList = paymentService.fetchPendingBillNosForSupplier(supplier_name_combo.getValue());
bill_no_combo.setItems(FXCollections.observableArrayList(billNoComboList));
} catch (SQLException ex) {
Utils.showAlert(ex.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,10 @@ private void deleteEntry(ActionEvent event) {
@FXML
private void printPayment(ActionEvent event) {
try {
Connection conn = DatabaseHandler.getInstance().getConnection();
String jrxmlFileName = "/jrxml/Payment.jrxml";
JasperReport jasperReport =
JasperCompileManager.compileReport(getClass().getResourceAsStream(jrxmlFileName));
Map<String, Object> 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);
paymentService.generatePdf(voucher_no_field.getText());
Utils.launchPdf(Constants.REPORT_FILE_NAME);
Utils.showAlert("Report Successfully Generated", 1);
} catch (IOException | JRException ex) {
} catch (IOException | JRException | SQLException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import javafx.scene.control.TextField;
import satyamconsignment.common.Utils;
import satyamconsignment.repository.BuyerRepository;
import satyamconsignment.repository.CollectionRepository;
import satyamconsignment.service.BuyerService;
import satyamconsignment.service.CollectionService;

public class BuyerController implements Initializable {

Expand Down Expand Up @@ -43,7 +45,7 @@ public class BuyerController implements Initializable {

@Override
public void initialize(URL url, ResourceBundle rb) {
buyerService = new BuyerService(new BuyerRepository());
buyerService = new BuyerService(new BuyerRepository(), new CollectionService(new CollectionRepository()));
refreshList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import satyamconsignment.common.Utils;
import satyamconsignment.repository.PaymentRepository;
import satyamconsignment.repository.SupplierRepository;
import satyamconsignment.service.PaymentService;
import satyamconsignment.service.SupplierService;

public class SupplierController implements Initializable {
Expand Down Expand Up @@ -43,7 +45,7 @@ public class SupplierController implements Initializable {

@Override
public void initialize(URL url, ResourceBundle rb) {
supplierService = new SupplierService(new SupplierRepository());
supplierService = new SupplierService(new SupplierRepository(), new PaymentService(new PaymentRepository()));
refreshList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
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;
Expand All @@ -20,10 +17,11 @@
import javafx.scene.control.ToggleGroup;
import net.sf.jasperreports.engine.*;
import satyamconsignment.common.Constants;
import satyamconsignment.common.DatabaseHandler;
import satyamconsignment.common.Utils;
import satyamconsignment.repository.BuyerRepository;
import satyamconsignment.repository.CollectionRepository;
import satyamconsignment.service.BuyerService;
import satyamconsignment.service.CollectionService;

public class BuyerLedgerController implements Initializable {

Expand All @@ -45,9 +43,11 @@ public class BuyerLedgerController implements Initializable {
@FXML
private Button launch_pdf_btn;

private BuyerService buyerService;

@Override
public void initialize(URL url, ResourceBundle rb) {
BuyerService buyerService = new BuyerService(new BuyerRepository());
buyerService = new BuyerService(new BuyerRepository(), new CollectionService(new CollectionRepository()));
try {
List<String> buyerNames = buyerService.getAllBuyers();
buyer_name_combo.setItems(FXCollections.observableArrayList(buyerNames));
Expand All @@ -59,27 +59,12 @@ public void initialize(URL url, ResourceBundle rb) {

@FXML
private void generatePDF(ActionEvent event) {
Connection conn = DatabaseHandler.getInstance().getConnection();

String jrxmlFileName;
if (agewise_outstanding_radio.isSelected()) {
jrxmlFileName = "BuyerLedgerAge.jrxml";
} else {
jrxmlFileName = "BuyerLedger.jrxml";
}
String jrxmlFilePath = "/jrxml/" + jrxmlFileName;

Map<String, Object> 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);
buyerService.generatePdf(
buyer_name_combo.getSelectionModel().getSelectedItem(), agewise_outstanding_radio.isSelected());
Utils.launchPdf(Constants.REPORT_FILE_NAME);
Utils.showAlert("Report Successfully Generated", 1);
} catch (IOException | JRException ex) {
} catch (SQLException | IOException | JRException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(BuyerLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
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;
Expand All @@ -20,9 +17,10 @@
import javafx.scene.control.ToggleGroup;
import net.sf.jasperreports.engine.*;
import satyamconsignment.common.Constants;
import satyamconsignment.common.DatabaseHandler;
import satyamconsignment.common.Utils;
import satyamconsignment.repository.PaymentRepository;
import satyamconsignment.repository.SupplierRepository;
import satyamconsignment.service.PaymentService;
import satyamconsignment.service.SupplierService;

public class SupplierLedgerController implements Initializable {
Expand All @@ -45,9 +43,11 @@ public class SupplierLedgerController implements Initializable {
@FXML
private Button launch_pdf_btn;

private SupplierService supplierService;

@Override
public void initialize(URL url, ResourceBundle rb) {
SupplierService supplierService = new SupplierService(new SupplierRepository());
supplierService = new SupplierService(new SupplierRepository(), new PaymentService(new PaymentRepository()));
try {
List<String> supplierList = supplierService.getAllSuppliers();
supplier_name_combo.setItems(FXCollections.observableArrayList(supplierList));
Expand All @@ -59,26 +59,12 @@ public void initialize(URL url, ResourceBundle rb) {

@FXML
private void generatePDF(ActionEvent event) {
Connection conn = DatabaseHandler.getInstance().getConnection();

String jrxmlFileName;
if (agewise_outstanding_radio.isSelected()) {
jrxmlFileName = "SupplierLedgerAge.jrxml";
} else {
jrxmlFileName = "SupplierLedger.jrxml";
}
String jrxmlFilePath = "/jrxml/" + jrxmlFileName;
Map<String, Object> 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);
supplierService.generatePdf(
supplier_name_combo.getSelectionModel().getSelectedItem(), agewise_outstanding_radio.isSelected());
Utils.launchPdf(Constants.REPORT_FILE_NAME);
Utils.showAlert("Report Successfully Generated", 1);
} catch (JRException | IOException ex) {
} catch (IOException | SQLException | JRException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(SupplierLedgerController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
Expand Down
Loading
Loading