Search in sources :

Example 1 with WalletUtil

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);
}
Also used : Query(com.google.firebase.database.Query) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) OrderDetailAdapter(com.example.asus.onlinecanteen.adapter.OrderDetailAdapter) ValueEventListener(com.google.firebase.database.ValueEventListener) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil)

Example 2 with WalletUtil

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) {
                    }
                });
            }
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Intent(android.content.Intent) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil) View(android.view.View)

Example 3 with WalletUtil

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) {
                    }
                });
            }
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Intent(android.content.Intent) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil) View(android.view.View)

Example 4 with WalletUtil

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();
            }
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) CartActivityAdapter(com.example.asus.onlinecanteen.adapter.CartActivityAdapter) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) ValueEventListener(com.google.firebase.database.ValueEventListener) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil) PurchasedItem(com.example.asus.onlinecanteen.model.PurchasedItem) Cart(com.example.asus.onlinecanteen.model.Cart)

Example 5 with WalletUtil

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) {
                }
            });
        }
    });
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) DatabaseError(com.google.firebase.database.DatabaseError) Intent(android.content.Intent) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Intent (android.content.Intent)5 View (android.view.View)5 WalletUtil (com.example.asus.onlinecanteen.utils.WalletUtil)5 DataSnapshot (com.google.firebase.database.DataSnapshot)5 DatabaseError (com.google.firebase.database.DatabaseError)5 ValueEventListener (com.google.firebase.database.ValueEventListener)5 TextView (android.widget.TextView)3 Transaction (com.example.asus.onlinecanteen.model.Transaction)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 CartActivityAdapter (com.example.asus.onlinecanteen.adapter.CartActivityAdapter)1 OrderDetailAdapter (com.example.asus.onlinecanteen.adapter.OrderDetailAdapter)1 Cart (com.example.asus.onlinecanteen.model.Cart)1 PurchasedItem (com.example.asus.onlinecanteen.model.PurchasedItem)1 TopUp (com.example.asus.onlinecanteen.model.TopUp)1 Query (com.google.firebase.database.Query)1