Commit 03a20a58 authored by Bhavesh Yadav's avatar Bhavesh Yadav

Finished checkout from firebase

parent 2c5c3a4b
...@@ -54,18 +54,25 @@ public class checkin extends Activity { ...@@ -54,18 +54,25 @@ public class checkin extends Activity {
if(!cd.getName().isEmpty() && !cd.getSlot().isEmpty() && !cd.getVehicle_no().isEmpty()){ if(!cd.getName().isEmpty() && !cd.getSlot().isEmpty() && !cd.getVehicle_no().isEmpty()){
sqlite_ops so=new sqlite_ops(this); sqlite_ops so=new sqlite_ops(this);
if(so.check_in(cd)){ so.check_in(cd,this);
Intent i=new Intent(checkin.this,ticket.class); //add waiting popup
i.putExtra("ticket_no",so.lastIndexRecords());
startActivity(i);
} }
else{ else{
Toast.makeText(this,"Error in inserting data",Toast.LENGTH_SHORT).show(); Toast.makeText(this,"Fields can not be empty",Toast.LENGTH_SHORT).show();
} }
} }
else{
Toast.makeText(this,"Fields can not be empty",Toast.LENGTH_SHORT).show();
public void checkinSuccess(String ticketNo) {
Intent i=new Intent(checkin.this,ticket.class);
i.putExtra("ticket_no",ticketNo);
i.putExtra("checkin",1);
startActivity(i);
} }
public void checkinFailure() {
Toast.makeText(this,"Error in inserting data",Toast.LENGTH_SHORT).show();
} }
@Override @Override
......
...@@ -72,20 +72,30 @@ public class checkout extends Activity { ...@@ -72,20 +72,30 @@ public class checkout extends Activity {
} }
else{ else{
sqlite_ops so=new sqlite_ops(this); sqlite_ops so=new sqlite_ops(this);
if(so.check_out(slot_number,Long.parseLong(ticket_number))){ so.check_out(slot_number,ticket_number,this);
}
}
}
public void checkoutSuccess(Long checkoutDateTime) {
Intent i = new Intent(this, ticket.class); Intent i = new Intent(this, ticket.class);
long datetime = Long.parseLong(checkoutDateTime.toString());
Date date = new Date(datetime*1000);
Format format = new SimpleDateFormat("dd/MM/yy HH:mm");
String dateString = format.format(date);
ticketData.add(6,dateString);
i.putExtra("ticket_data", ticketData); i.putExtra("ticket_data", ticketData);
i.putExtra("ticket_no",ticket_number); i.putExtra("ticket_no",ticket_number);
i.putExtra("checkout",true); i.putExtra("checkout",true);
startActivity(i); startActivity(i);
Toast.makeText(this,"Successfully,Checked Out",Toast.LENGTH_SHORT).show(); Toast.makeText(this,"Successfully,Checked Out",Toast.LENGTH_SHORT).show();
} }
else{
public void checkoutFailed() {
Toast.makeText(this,"Error! Contact Developer",Toast.LENGTH_SHORT).show(); Toast.makeText(this,"Error! Contact Developer",Toast.LENGTH_SHORT).show();
} }
}
}
}
public void checkout(View view) { public void checkout(View view) {
AlertDialog.Builder builder= new AlertDialog.Builder(this); AlertDialog.Builder builder= new AlertDialog.Builder(this);
builder.setTitle("Do you want to Checkout?"); builder.setTitle("Do you want to Checkout?");
...@@ -112,6 +122,7 @@ public class checkout extends Activity { ...@@ -112,6 +122,7 @@ public class checkout extends Activity {
Intent i = new Intent(this, ticket.class); Intent i = new Intent(this, ticket.class);
i.putExtra("ticket_data", ticketData); i.putExtra("ticket_data", ticketData);
i.putExtra("ticket_no", ticket_number); i.putExtra("ticket_no", ticket_number);
i.putExtra("reprint",1);
startActivity(i); startActivity(i);
} }
} }
......
...@@ -67,6 +67,7 @@ public class sqlite_ops extends SQLiteOpenHelper{ ...@@ -67,6 +67,7 @@ public class sqlite_ops extends SQLiteOpenHelper{
public void initFirebase() { public void initFirebase() {
//AddSlotsToFirebase(); //AddSlotsToFirebase();
fdb = FirebaseFirestore.getInstance(); fdb = FirebaseFirestore.getInstance();
AddSlotsToFirebase();
} }
public void AddSlotsToFirebase() { public void AddSlotsToFirebase() {
...@@ -182,7 +183,7 @@ public class sqlite_ops extends SQLiteOpenHelper{ ...@@ -182,7 +183,7 @@ public class sqlite_ops extends SQLiteOpenHelper{
return true; return true;
} }
public boolean check_in(checkin_details cd){ public boolean check_in(checkin_details cd,final checkin ci){
Long timeStamp = System.currentTimeMillis()/1000; Long timeStamp = System.currentTimeMillis()/1000;
Map<String, Object> parkingRecord = new HashMap<>(); Map<String, Object> parkingRecord = new HashMap<>();
...@@ -200,12 +201,15 @@ public class sqlite_ops extends SQLiteOpenHelper{ ...@@ -200,12 +201,15 @@ public class sqlite_ops extends SQLiteOpenHelper{
@Override @Override
public void onSuccess(DocumentReference docref) { public void onSuccess(DocumentReference docref) {
Log.d(TAG, "Parking record successfully written!"); Log.d(TAG, "Parking record successfully written!");
docref.update("ticket_no",docref.getId());
ci.checkinSuccess(docref.getId());
} }
}) })
.addOnFailureListener(new OnFailureListener() { .addOnFailureListener(new OnFailureListener() {
@Override @Override
public void onFailure(@NonNull Exception e) { public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error writing document", e); Log.w(TAG, "Error writing document", e);
ci.checkinFailure();
} }
}); });
final CollectionReference collection= fdb.collection("slots"); final CollectionReference collection= fdb.collection("slots");
...@@ -306,31 +310,49 @@ public class sqlite_ops extends SQLiteOpenHelper{ ...@@ -306,31 +310,49 @@ public class sqlite_ops extends SQLiteOpenHelper{
return slots; return slots;
} }
public ArrayList getTicketDetails(long ticket_no) { public void getTicketDetails(String ticket_no,final ticket tc) {
ArrayList al=new ArrayList(); // ArrayList al=new ArrayList();
SQLiteDatabase db=this.getWritableDatabase(); // SQLiteDatabase db=this.getWritableDatabase();
Cursor cr=db.query("records",new String []{"tkt_no","slot","vehicle","check_in","check_out"},"tkt_no=?",new String[]{Long.toString(ticket_no)},null,null,null,null); // Cursor cr=db.query("records",new String []{"tkt_no","slot","vehicle","check_in","check_out"},"tkt_no=?",new String[]{Long.toString(ticket_no)},null,null,null,null);
if(cr!=null){ // if(cr!=null){
cr.moveToFirst(); // cr.moveToFirst();
if(cr.getCount()>0){ // if(cr.getCount()>0){
al.add(0,cr.getString(cr.getColumnIndex("tkt_no"))); // al.add(0,cr.getString(cr.getColumnIndex("tkt_no")));
al.add(1,cr.getString(cr.getColumnIndex("slot"))); // al.add(1,cr.getString(cr.getColumnIndex("slot")));
al.add(2,cr.getString(cr.getColumnIndex("vehicle"))); // al.add(2,cr.getString(cr.getColumnIndex("vehicle")));
al.add(3,cr.getString(cr.getColumnIndex("check_in"))); // al.add(3,cr.getString(cr.getColumnIndex("check_in")));
al.add(4,cr.getString(cr.getColumnIndex("check_out"))); // al.add(4,cr.getString(cr.getColumnIndex("check_out")));
} // }
else{ // else{
al.add(0,ticket_no); // al.add(0,ticket_no);
al.add(""); // al.add("");
al.add(""); // al.add("");
al.add(""); // al.add("");
//
// }
//
// }
// db.close();
fdb = FirebaseFirestore.getInstance();
DocumentReference docRef = fdb.collection("records").document(ticket_no);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot document) {
ArrayList al = new ArrayList();
// City city = documentSnapshot.getData();
al.add(0,document.getId());
al.add(1,document.getData().get("slot"));
al.add(2,document.getData().get("vehicle"));
al.add(3,document.getData().get("checkInTimeDate"));
al.add(4,document.getData().get("name"));
al.add(5,document.getData().get("mobile"));
al.add(6,document.getData().get("status"));
Log.d("Ticket","getting slot ticket"+document.getData().toString());
tc.showTicketDetails(al);
} }
});
} }
db.close();
return al;
}
public long lastIndexRecords(){ public long lastIndexRecords(){
SQLiteDatabase db=this.getReadableDatabase(); SQLiteDatabase db=this.getReadableDatabase();
...@@ -435,12 +457,45 @@ public class sqlite_ops extends SQLiteOpenHelper{ ...@@ -435,12 +457,45 @@ public class sqlite_ops extends SQLiteOpenHelper{
}); });
} }
public boolean check_out(String slot,Long tkt){ public void check_out(String slot,final String tkt,final checkout co){
SQLiteDatabase db= this.getWritableDatabase(); // SQLiteDatabase db= this.getWritableDatabase();
db.execSQL("update records set check_out=current_timestamp,isempty=1 where tkt_no="+tkt); // db.execSQL("update records set check_out=current_timestamp,isempty=1 where tkt_no="+tkt);
db.execSQL("update slots set status=0 where slot='"+slot+"'"); // db.execSQL("update slots set status=0 where slot='"+slot+"'");
db.close(); // db.close();
return true; // return true;
final Long checkoutTimeStamp = System.currentTimeMillis()/1000;
fdb = FirebaseFirestore.getInstance();
final CollectionReference collection= fdb.collection("slots");
fdb.collection("slots").whereEqualTo("slot",slot).get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()) {
QuerySnapshot documentSnapshot = task.getResult();
for (QueryDocumentSnapshot document : task.getResult()) {
String id = document.getId();
collection.document(id).update("status", 0);
fdb.collection("records").document(tkt).update(
"checkOutDateTime",checkoutTimeStamp,
"status","0"
).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()) {
co.checkoutSuccess(checkoutTimeStamp);
}else {
co.checkoutFailed();
}
}
});
}
}
else {
Log.d("Checkout","slot update failed");
}
}
});
} }
public void getAllFilledSlotDetails(final currentParks cp){ public void getAllFilledSlotDetails(final currentParks cp){
......
...@@ -8,7 +8,10 @@ import android.view.View; ...@@ -8,7 +8,10 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
public class ticket extends Activity { public class ticket extends Activity {
TextView slot,tkt,time_tv,date_tv,vehicle,ticket_title,checkout_label,checkout_time; TextView slot,tkt,time_tv,date_tv,vehicle,ticket_title,checkout_label,checkout_time;
...@@ -30,26 +33,31 @@ public class ticket extends Activity { ...@@ -30,26 +33,31 @@ public class ticket extends Activity {
checkout_date=findViewById(R.id.checkout_date); checkout_date=findViewById(R.id.checkout_date);
checkout_date_label=findViewById(R.id.checkout_date_label); checkout_date_label=findViewById(R.id.checkout_date_label);
Intent i=getIntent(); Intent i=getIntent();
long ticket_no; String ticket_no;
if(i.hasExtra("ticket_data")){ if(i.hasExtra("ticket_data")){
// Bundle b=i.getExtras();
// ticket_no=b.getLong("ticket_no");
ticketData = (ArrayList<String>) i.getSerializableExtra("ticket_data"); ticketData = (ArrayList<String>) i.getSerializableExtra("ticket_data");
ticket_no = i.getExtras().getString("ticket_no");
} }
else{ else{
ticket_no=10000;
} }
//sqlite_ops so=new sqlite_ops(this); if(i.hasExtra("checkin")) {
//ArrayList data=so.getTicketDetails(ticket_no); ticket_no=i.getExtras().getString("ticket_no");
sqlite_ops so = new sqlite_ops(this);
so.getTicketDetails(ticket_no,this);
//waiting popup
}
if(i.hasExtra("checkout")){ if(i.hasExtra("checkout")){
ticket_no=i.getExtras().getString("ticket_no");
// sqlite_ops so=new sqlite_ops(this);
// ticketData=so.getTicketDetails(ticket_no);
Log.d("CHECKOUT","successfully checkout out"); Log.d("CHECKOUT","successfully checkout out");
ticket_title.setText("Checkout Receipt"); ticket_title.setText("Checkout Receipt");
checkout_label.setVisibility(View.VISIBLE); checkout_label.setVisibility(View.VISIBLE);
checkout_time.setVisibility(View.VISIBLE); checkout_time.setVisibility(View.VISIBLE);
checkout_date.setVisibility(View.VISIBLE); checkout_date.setVisibility(View.VISIBLE);
checkout_date_label.setVisibility(View.VISIBLE); checkout_date_label.setVisibility(View.VISIBLE);
String checkout_date_data=ticketData.get(4).toString(); String checkout_date_data=ticketData.get(6).toString();
String[] checkoutdateandtime=checkout_date_data.split(" "); String[] checkoutdateandtime=checkout_date_data.split(" ");
checkout_date.setText(checkoutdateandtime[0]); checkout_date.setText(checkoutdateandtime[0]);
checkout_time.setText(checkoutdateandtime[1]); checkout_time.setText(checkoutdateandtime[1]);
...@@ -60,14 +68,30 @@ public class ticket extends Activity { ...@@ -60,14 +68,30 @@ public class ticket extends Activity {
checkout_date.setVisibility(View.INVISIBLE); checkout_date.setVisibility(View.INVISIBLE);
checkout_date_label.setVisibility(View.INVISIBLE); checkout_date_label.setVisibility(View.INVISIBLE);
} }
if(i.hasExtra("ticket_data")) {
slot.setText(ticketData.get(1).toString()); slot.setText(ticketData.get(1).toString());
tkt.setText(ticketData.get(0).toString().substring(0,4).toUpperCase()); tkt.setText(ticketData.get(0).toString().substring(0, 4).toUpperCase());
String date_data=ticketData.get(3).toString(); String date_data = ticketData.get(3).toString();
String[] dateandtime=date_data.split(" "); String[] dateandtime = date_data.split(" ");
date_tv.setText(dateandtime[0]); date_tv.setText(dateandtime[0]);
time_tv.setText(dateandtime[1]); time_tv.setText(dateandtime[1]);
vehicle.setText(ticketData.get(2).toString()); vehicle.setText(ticketData.get(2).toString());
}
}
public void showTicketDetails(ArrayList ticketData) {
slot.setText(ticketData.get(1).toString());
tkt.setText(ticketData.get(0).toString().substring(0,4).toUpperCase());
long datetime = Long.parseLong(ticketData.get(3).toString());
Date date = new Date(datetime*1000);
Format format = new SimpleDateFormat("dd/MM/yy HH:mm");
String dateString = format.format(date);
//String date_data=ticketData.get(3).toString();
String[] dateandtime=dateString.split(" ");
date_tv.setText(dateandtime[0]);
time_tv.setText(dateandtime[1]);
vehicle.setText(ticketData.get(2).toString());
} }
public void Print(View view) { public void Print(View view) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment