Skip to content

Commit

Permalink
Merge pull request #20 from dinesh-it/venkatesh
Browse files Browse the repository at this point in the history
View Bill Details Completed
  • Loading branch information
dinesh-it committed Sep 14, 2015
2 parents 9524838 + 987343b commit fdffc12
Show file tree
Hide file tree
Showing 5 changed files with 571 additions and 26 deletions.
64 changes: 62 additions & 2 deletions src/DataBaseInterface/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.EntityManager;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

import org.hibernate.Query;
import org.hibernate.SQLQuery;

import Util.*;
Expand Down Expand Up @@ -465,7 +470,6 @@ public List<?> get_sms_queue() {
Session session = factory.openSession();
List<?> data = null;
try{

data = session.createQuery("FROM SMSQueue WHERE sent = 'f'").list();
}catch (HibernateException e) {
e.printStackTrace();
Expand All @@ -476,6 +480,44 @@ public List<?> get_sms_queue() {
return data;
}

public List<Object[]> get_bill_details(){

Session session = factory.openSession();

List<Object[]> result = null;

try{
// Query have to be optimize (instead of get all columns, should fetch required columns)
//fetching particular columns throws error.

SQLQuery query = session.createSQLQuery(
"SELECT *"
+ " FROM service_detail as sd"
+ " JOIN service_bill as sb ON sd.service_bill_id = sb.id"
+ " JOIN service_particulars as sp ON sd.service_particular_id = sp.id"
+ " JOIN customer_vehicle as veh ON sb.vehicle_id = veh.id"
+ " JOIN customer as cus ON veh.customer_id = cus.id order by sb.id"
);

query.addEntity(ServiceDetail.class);
query.addEntity(ServiceBill.class);
query.addEntity(ServiceParticulars.class);
query.addEntity(CustomerVehicle.class);
query.addEntity(Customer.class);

result = query.list();

}catch (HibernateException e) {

e.printStackTrace();
Logger.log.severe(e.toString());
}finally {
session.close();
}
return result;
}


public List<Object[]> get_single_bill_detail(int bill_id){
Session session = factory.openSession();

Expand All @@ -497,15 +539,33 @@ public List<Object[]> get_single_bill_detail(int bill_id){
query.addEntity(ServiceBill.class);
query.addEntity(CustomerVehicle.class);
query.addEntity(Customer.class);

result = query.list();


}catch (HibernateException e) {

e.printStackTrace();
Logger.log.severe(e.toString());
}finally {
session.close();
}
return result;
}

public ServiceBill get_service_bill(int vehicle_id, String date_str ) {
System.out.println(vehicle_id + " " + date_str);
Session session = factory.openSession();
ServiceBill obj_service_bill = null;
int epoch = Time.get_epoch(date_str, "dd/MM/yyyy HH:mm:ss");
try{
obj_service_bill = (ServiceBill)session.createQuery("FROM ServiceBill WHERE vehicle_id = '" + vehicle_id + "' and created_epoch = " + epoch).uniqueResult();
}catch (HibernateException e) {
e.printStackTrace();
Logger.log.severe(e.toString());
}finally {
session.close();
}

return obj_service_bill;
}
}
4 changes: 2 additions & 2 deletions src/DataBaseInterface/ServiceDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class ServiceDetail {

public ServiceDetail(){}

public ServiceDetail(Integer service_particulars_id, Integer service_bill_id,Integer quantity, double amount){
this.service_particular_id = service_particulars_id;
public ServiceDetail(Integer service_particular_id, Integer service_bill_id,Integer quantity, double amount){
this.service_particular_id = service_particular_id;
this.service_bill_id = service_bill_id;
this.quantity = quantity;
this.amount = amount;
Expand Down
19 changes: 11 additions & 8 deletions src/UserInterface/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ public class MainFrame extends JFrame {
static public JPanel pnl_home;
static MainFrame frame;

/**
* Launch the application.
*/
public static void main(String[] args) {

ProgressBar.showProgress("Loading Components....", 10);
Handler.getInstance();
ProgressBar.showProgress("Launching Application..", ProgressBar.MAXIMUM_VALUE);
ProgressBar.showProgress("Loading Components....", 10);
Handler.getInstance();
ProgressBar.showProgress("Launching Application..", ProgressBar.MAXIMUM_VALUE);

EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Expand Down Expand Up @@ -144,7 +141,7 @@ public void actionPerformed(ActionEvent e) {

// Title Lable
// TODO have to add icon
JLabel lbl_title = new JLabel("ABHI TRAVELS AND WHEELS");
JLabel lbl_title = new JLabel("ABHI WHEELS");
lbl_title.setForeground(new Color(210, 105, 30));
lbl_title.setFont(new Font("URW Bookman L", Font.ITALIC, 32));
lbl_title.setHorizontalAlignment(SwingConstants.CENTER);
Expand Down Expand Up @@ -247,6 +244,12 @@ public void actionPerformed(ActionEvent e) {

pnl_sub_wheel.add(btn_view_wheel);

btn_view_wheel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pnl_wheels_view obj_wheels_view = new pnl_wheels_view();
setContentPane(obj_wheels_view);
}
});
// update wheel window navigation button
JButton btn_update_wheel = new JButton("Edit Wheel Bill");
btn_update_wheel.setFont(btn_font);
Expand Down
35 changes: 21 additions & 14 deletions src/UserInterface/pnl_wheels_add.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import javax.swing.JScrollPane;
import javax.swing.JButton;

import DataBaseInterface.*;

import javax.swing.ListSelectionModel;

import java.awt.Font;

import Util.*;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

import javax.swing.JFormattedTextField;
import javax.swing.JTextArea;


public class pnl_wheels_add extends JPanel implements TableModelListener {
/**
*
*/

private static final long serialVersionUID = 1L;

private JTextField txt_mobile_no, txt_customer_name, txt_vehicle_make, txt_date, txt_time;
private JTextArea txt_comment;
private JTable tbl_particulars;
Expand All @@ -66,6 +66,8 @@ public pnl_wheels_add() {
add(pnl_customer_details);
pnl_customer_details.setLayout(null);



int now_epoch = Time.now();

JLabel lbl_mobile_no = new JLabel("Mobile No");
Expand Down Expand Up @@ -201,9 +203,7 @@ public void actionPerformed(ActionEvent e) {
o[1] = sp.getService_name();

boolean is_multi = sp.isIs_multiple();
if(is_multi){
o[2] = new Integer(1);
} else {
if(!is_multi){
o[2] = "NA";
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public void actionPerformed(ActionEvent e) {
txt_comment.setBounds(247, 476, 393, 49);
add(txt_comment);

JButton btnTestBill = new JButton("Test Bill");
/*JButton btnTestBill = new JButton("Test Bill");
btnTestBill.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Wheel bill print preview and print
Expand All @@ -262,7 +262,7 @@ public void actionPerformed(ActionEvent e) {
}
});
btnTestBill.setBounds(733, 570, 117, 25);
add(btnTestBill);
add(btnTestBill);*/

txt_vehicle_no.addFocusListener(new FocusAdapter() {
@Override
Expand Down Expand Up @@ -467,7 +467,7 @@ private boolean validate_details() {
c_mobile = txt_mobile_no.getText();
date = txt_date.getText();
time = txt_time.getText();

if(!v_num.matches(Formatter.VEHICLE_PATTERN)){
alert("Vehicle number is invalid, Please correct it");
txt_vehicle_no.requestFocus();
Expand Down Expand Up @@ -526,7 +526,7 @@ public void tableChanged(TableModelEvent e) {
int column = e.getColumn();
Pattern pattern = Pattern.compile("(^\\d+\\.?\\d*$)");

// validation for accept only numbers

String current_cell_str = tbl_particulars.getValueAt(row, column).toString();
if((! current_cell_str.trim().isEmpty()) && (!pattern.matcher(current_cell_str).find())){
if(column == 3 )
Expand All @@ -542,6 +542,7 @@ else if(column == 2)
// parsing null value will throw NumberFormatException
// To avoid that exception amount stored in string
String str_amount = tbl_particulars.getValueAt(row, 3).toString();


if(! str_amount.trim().isEmpty()){

Expand All @@ -551,8 +552,14 @@ else if(column == 2)
if(is_multiple[row].toString() == "false") {
total = amount;
} else {
int quantity = Integer.parseInt(tbl_particulars.getValueAt(row, 2).toString());
total = amount * quantity;

int quan = 1;
if( tbl_particulars.getValueAt(row, 2) != null)
quan = Integer.parseInt(tbl_particulars.getValueAt(row, 2).toString());
else
tbl_particulars.setValueAt(new Integer(1), row, 2);

total = amount * quan;
}

tbl_particulars.setValueAt(new Double(total), row, 4);
Expand Down
Loading

0 comments on commit fdffc12

Please sign in to comment.