use of com.example.asus.onlinecanteen.utils.WalletUtil in project OnlineCanteen by josephgunawan97.
the class MerchantOrderDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_merchant_order_detail);
firebaseDatabase = FirebaseDatabase.getInstance();
reference = firebaseDatabase.getReference("transactions");
intent = getIntent();
pos = intent.getIntExtra("Position", 0);
transactionHistory = (ArrayList<Transaction>) intent.getSerializableExtra("Transaction");
transaction = transactionHistory.get(pos);
mAuth = FirebaseAuth.getInstance();
// Initialize views
transactiondate = findViewById(R.id.transaction_date);
username = findViewById(R.id.username);
location = findViewById(R.id.user_location);
grandTotal = findViewById(R.id.transaction_detail_amount);
orderStatus = findViewById(R.id.order_status);
acceptButton = findViewById(R.id.acceptOrder);
declineButton = findViewById(R.id.declineOrder);
scanQR = findViewById(R.id.scan_qr);
if (transaction.getDeliveryStatus() == 0) {
acceptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WalletUtil walletUtil = new WalletUtil();
walletUtil.debitAmount(mAuth.getCurrentUser().getUid(), transaction.getTotalPrice());
Toast.makeText(getApplicationContext(), "Order accepted", Toast.LENGTH_LONG).show();
Query query = reference.orderByChild("purchaseDate").equalTo(transaction.getPurchaseDate());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child : snapshot.getChildren()) {
child.getRef().child("deliveryStatus").setValue(1);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Intent intent = new Intent(MerchantOrderDetailActivity.this, MainActivityMerchant.class);
startActivity(intent);
finish();
}
});
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Order declined", Toast.LENGTH_LONG).show();
Query query = reference.orderByChild("purchaseDate").equalTo(transaction.getPurchaseDate());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child : snapshot.getChildren()) {
child.getRef().child("deliveryStatus").setValue(4);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Intent intent = new Intent(MerchantOrderDetailActivity.this, MainActivityMerchant.class);
startActivity(intent);
finish();
}
});
} else {
acceptButton.setClickable(false);
acceptButton.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
declineButton.setClickable(false);
declineButton.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
}
scanQR.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), QrActivity.class);
i.putExtra("Location", "order");
i.putExtra("Transaction", transactionHistory);
i.putExtra("Position", pos);
startActivityForResult(i, SECOND_ACTIVITY_REQUEST_CODE);
}
});
// Set views
transactiondate.setText(Transaction.getPurchasedDateString(transaction.getPurchaseDate()));
username.setText(transaction.getName());
location.setText(transaction.getLocation());
grandTotal.setText("Rp " + String.valueOf(transaction.getTotalPrice()));
// TO BE CHANGED LATER
orderStatus.setText(statusString(transaction.getDeliveryStatus()));
// Adapter for order items list
detailAdapter = new OrderDetailAdapter(transaction.getItems());
itemsRecyclerView = findViewById(R.id.transaction_detail_items);
layoutManager = new LinearLayoutManager(getApplicationContext());
itemsRecyclerView.setLayoutManager(layoutManager);
itemsRecyclerView.setAdapter(detailAdapter);
}
use of com.example.asus.onlinecanteen.utils.WalletUtil in project OnlineCanteen by josephgunawan97.
the class AdminStoreWithdrawal method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_store_withdrawal);
firebaseAuth = FirebaseAuth.getInstance();
emailET = (EditText) findViewById(R.id.withdrawEmail);
amountET = (EditText) findViewById(R.id.withdrawAmount);
withdrawButton = (Button) findViewById(R.id.withdrawButton);
withdrawButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (validateForm()) {
email = emailET.getText().toString();
email = email.replaceAll(Pattern.quote("."), ",");
amount = Integer.parseInt(amountET.getText().toString());
emailDatabase = FirebaseDatabase.getInstance().getReference();
emailDatabase.child("emailtouid").child(email).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
WalletUtil walletUtil = new WalletUtil();
String id = dataSnapshot.getValue().toString();
walletUtil.creditAmount(id, amount);
Intent intent = new Intent(AdminStoreWithdrawal.this, MainActivityAdmin.class);
startActivity(intent);
finish();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
});
}
use of com.example.asus.onlinecanteen.utils.WalletUtil in project OnlineCanteen by josephgunawan97.
the class AdminTopUpActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_top_up);
firebaseAuth = FirebaseAuth.getInstance();
emailET = (EditText) findViewById(R.id.topUpEmail);
amountET = (EditText) findViewById(R.id.topUpAmount);
topUpButton = (Button) findViewById(R.id.topUpButton);
topUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (validateForm()) {
email = emailET.getText().toString();
email = email.replaceAll(Pattern.quote("."), ",");
amount = Integer.parseInt(amountET.getText().toString());
emailDatabase = FirebaseDatabase.getInstance().getReference();
emailDatabase.child("emailtouid").child(email).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
WalletUtil walletUtil = new WalletUtil();
String id = dataSnapshot.getValue().toString();
walletUtil.debitAmount(id, amount);
Intent intent = new Intent(AdminTopUpActivity.this, MainActivityAdmin.class);
startActivity(intent);
finish();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
});
}
use of com.example.asus.onlinecanteen.utils.WalletUtil in project OnlineCanteen by josephgunawan97.
the class CartActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
cart = (ArrayList<Cart>) getIntent().getSerializableExtra("Cart");
cartActivityAdapter = new CartActivityAdapter(this, cart);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
walletUtil = new WalletUtil();
notificationRef = FirebaseDatabase.getInstance().getReference().child("notifications");
// Calculating the grand total
for (Cart c : cart) {
total += c.getTotalPrice(c);
}
// Initialize ListView
cartList = findViewById(R.id.cartList);
grandTotal = findViewById(R.id.grandTotal);
deliveryFee = findViewById(R.id.deliveryFee);
orderButton = findViewById(R.id.OrderButton);
locationEditText = findViewById(R.id.userLocation);
// Set views
grandTotal.setText("TOTAL: Rp " + total);
deliveryFee.setText("Delivery Fee : Rp ");
cartList.setAdapter(cartActivityAdapter);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!locationEditText.getText().toString().isEmpty()) {
// Make new transaction
walletRef = FirebaseDatabase.getInstance().getReference().child("wallet");
walletRef.child(user.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String valueString = dataSnapshot.getValue().toString();
int walletCash = Integer.parseInt(valueString);
// if wallet money >= total
if (walletCash >= total) {
ArrayList<PurchasedItem> items = new ArrayList<>();
for (Cart c : cart) {
PurchasedItem item = new PurchasedItem(c.getProductName(), c.getProductPrice(), c.getQuantity());
items.add(item);
}
Intent intent = getIntent();
Transaction transaction = new Transaction(intent.getStringExtra("Seller"), FirebaseAuth.getInstance().getUid(), items, locationEditText.getText().toString());
TransactionUtil.insert(transaction);
Toast.makeText(getApplicationContext(), "Transcation done", Toast.LENGTH_SHORT).show();
setResult(RESULT_OK);
// Make notification to the seller
HashMap<String, String> notificationData = new HashMap<>();
notificationData.put("from", transaction.getUid());
notificationData.put("type", "new order");
notificationRef.child(transaction.getSid()).push().setValue(notificationData);
// Go back to main menu
finish();
} else {
Toast.makeText(getApplicationContext(), "Not enough wallet cash, please top-up at our counter", Toast.LENGTH_SHORT).show();
finish();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
// Alert dialog if the location is not filled in
AlertDialog.Builder builder = new AlertDialog.Builder(CartActivity.this);
builder.setMessage("Please enter your location!").setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.setTitle("Error");
alert.show();
}
}
});
}
use of com.example.asus.onlinecanteen.utils.WalletUtil in project OnlineCanteen by josephgunawan97.
the class TopUpDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_topup_request);
firebaseDatabase = FirebaseDatabase.getInstance();
reference = firebaseDatabase.getReference("topuprequest");
intent = getIntent();
pos = intent.getIntExtra("Position", 0);
topupHistory = (ArrayList<TopUp>) intent.getSerializableExtra("topup");
topUp = topupHistory.get(pos);
mAuth = FirebaseAuth.getInstance();
transactiondate = findViewById(R.id.topup_detail_topup_date);
username = findViewById(R.id.request_name);
bankname = findViewById(R.id.bank_name);
transfername = findViewById(R.id.trans_name);
amount = findViewById(R.id.topup_detail_amount);
accept = findViewById(R.id.accept_request);
transferproof = findViewById(R.id.proofdetail);
transactiondate.setText(topUp.getRequestDateString(topUp.getRequestdate()));
transfername.setText(topUp.getTransfername());
bankname.setText(topUp.getBank());
amount.setText("Top-up Amount : " + Integer.toString(topUp.getAmount()));
if (topUp.getRequeststatus() == 1) {
accept.setEnabled(false);
}
if (topUp.getProofpicUrl() != null) {
Glide.with(transferproof.getContext()).load(topUp.getProofpicUrl()).into(transferproof);
}
FirebaseDatabase.getInstance().getReference("users").child(topUp.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.i(TopUpDetailActivity.class.getSimpleName(), "TRANS + " + dataSnapshot.getValue());
username.setText(dataSnapshot.child("name").getValue().toString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseDatabase.getInstance().getReference().child("wallet").child(topUp.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
WalletUtil walletUtil = new WalletUtil();
walletUtil.debitAmount(topUp.getUid(), topUp.getAmount());
Toast.makeText(getApplicationContext(), "Request accepted", Toast.LENGTH_LONG).show();
updateReq();
Intent intent = new Intent(getApplicationContext(), MainActivityAdmin.class);
startActivity(intent);
finish();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
Aggregations