Skip to content

Commit

Permalink
Add payment options for manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevansurendran authored and shivanshs9 committed Nov 22, 2020
1 parent 484fb71 commit 36ce54f
Show file tree
Hide file tree
Showing 11 changed files with 504 additions and 37 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/checkin/app/checkin/Shop/ShopModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void setWorkingTimerange(ObjectNode data) {
}

public enum PAYMENT_MODE {
CASH("csh"), PAYTM("ptm"), CARD("crd");
CASH("csh"), PAYTM("ptm"), CARD("crd"), UPI("upi");

public String tag;

Expand Down Expand Up @@ -274,8 +274,10 @@ public PAYMENT_MODE deserialize(JsonParser p, DeserializationContext ctxt) throw

public static String getPaymentMode(PAYMENT_MODE paymentMode) {
switch (paymentMode) {
case CASH:
return "via Cash";
case CARD:
return "via Card";
case UPI:
return "via Upi";
case PAYTM:
return "";
default:
Expand All @@ -286,10 +288,13 @@ public static String getPaymentMode(PAYMENT_MODE paymentMode) {
@DrawableRes
public static int getPaymentModeIcon(PAYMENT_MODE paymentMode) {
switch (paymentMode) {
case CASH:
return R.drawable.ic_cash_grey;
case CARD:
return R.drawable.ic_card;
case UPI:
return R.drawable.ic_payment_upi;
case PAYTM:
return R.drawable.ic_paytm_logo;
case CASH:
default:
return R.drawable.ic_cash_grey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ interface WebApiService {
fun putManageSessionBill(@Path("session_id") sessionId: Long, @Body data: ObjectNode): Call<GenericDetailModel>

@POST("sessions/manage/{session_id}/checkout/")
fun putSessionCheckout(@Path("session_id") sessionId: Long): Call<CheckoutStatusModel>
fun putSessionCheckout(@Path("session_id") sessionId: Long, @Body data: ObjectNode): Call<CheckoutStatusModel>

@POST("sessions/manage/new/")
fun postManageInitiateSession(@Body data: ObjectNode): Call<QRResultModel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class ManagerRepository private constructor(context: Context) : BaseRepository()
}.asLiveData
}

fun manageSessionCheckout(sessionId: Long): LiveData<Resource<CheckoutStatusModel>> {
fun manageSessionCheckout(sessionId: Long, body: ObjectNode): LiveData<Resource<CheckoutStatusModel>> {
return object : NetworkBoundResource<CheckoutStatusModel, CheckoutStatusModel>() {
override fun shouldUseLocalDb(): Boolean {
return false
}

override fun createCall(): LiveData<ApiResponse<CheckoutStatusModel>> {
return RetrofitLiveData(mWebService.putSessionCheckout(sessionId))
return RetrofitLiveData(mWebService.putSessionCheckout(sessionId, body))
}
}.asLiveData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.checkin.app.checkin.R;
import com.checkin.app.checkin.data.notifications.MESSAGE_TYPE;
import com.checkin.app.checkin.data.notifications.MessageModel;
import com.checkin.app.checkin.data.notifications.MessageObjectModel;
import com.checkin.app.checkin.data.notifications.MessageUtils;
import com.checkin.app.checkin.data.resource.Resource;
import com.checkin.app.checkin.manager.fragments.ManagerSessionPaymentOptionsBottomSheetFragment;
import com.checkin.app.checkin.manager.models.GuestContactModel;
import com.checkin.app.checkin.manager.models.ManagerSessionInvoiceModel;
import com.checkin.app.checkin.manager.viewmodels.ManagerSessionViewModel;
Expand All @@ -38,6 +31,13 @@
import com.checkin.app.checkin.session.models.SessionOrderedItemModel;
import com.checkin.app.checkin.utility.Utils;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand Down Expand Up @@ -77,9 +77,6 @@ public class ManagerSessionInvoiceActivity extends AppCompatActivity implements
private SessionBillModel mBillModel;
private BillHolder mBillHolder;

private boolean isRequestedCheckout;
private boolean isPromoApplied;

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand All @@ -101,6 +98,7 @@ public void onReceive(Context context, Intent intent) {
}
};


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -112,10 +110,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
long keySession = intent.getLongExtra(KEY_SESSION, 0L);
String tableName = intent.getStringExtra(TABLE_NAME);

updateRequestCheckoutStatus(intent.getBooleanExtra(IS_REQUESTED_CHECKOUT, false));

mViewModel = ViewModelProviders.of(this).get(ManagerSessionViewModel.class);

updateRequestCheckoutStatus(intent.getBooleanExtra(IS_REQUESTED_CHECKOUT, false));
ActionBar actionBar = getSupportActionBar();

if (actionBar != null) {
Expand Down Expand Up @@ -271,7 +268,7 @@ private void setUpContactUi(boolean enableOrDisabled, int drawable, int visibili
}

private void updateRequestCheckoutStatus(boolean isRequestedCheckout) {
this.isRequestedCheckout = isRequestedCheckout;
mViewModel.setmIsRequestedCheckout(isRequestedCheckout);
if (isRequestedCheckout) {
llRequestedCheckoutView.setVisibility(View.VISIBLE);
tvInvoiceChange.setVisibility(View.GONE);
Expand All @@ -282,17 +279,11 @@ private void updateRequestCheckoutStatus(boolean isRequestedCheckout) {
}

private void alertDialogForCloseSession() {
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("Are you sure you want to close session?")
.setNegativeButton("No", (dialog, which) -> dialog.cancel());
if (!isPromoApplied || isRequestedCheckout)
builder.setPositiveButton("Close session", (dialog, which) -> mViewModel.putSessionCheckout());
else
builder.setPositiveButton("Notify waiter", ((dialogInterface, i) -> mViewModel.requestSessionCheckout()));
if (!isPromoApplied && !isRequestedCheckout)
builder.setNeutralButton("Notify waiter", ((dialogInterface, i) -> mViewModel.requestSessionCheckout()));
builder.show();
ManagerSessionPaymentOptionsBottomSheetFragment bottomSheetFragment = ManagerSessionPaymentOptionsBottomSheetFragment.Companion.newInstance();
bottomSheetFragment.show(getSupportFragmentManager(), null);
}


private void updateDiscount() {
double percent = 0d;
try {
Expand All @@ -313,8 +304,7 @@ private void setupData(ManagerSessionInvoiceModel data) {
edInvoiceDiscount.setText(data.formatDiscountPercent());
mBillHolder.bind(data.getBill());
tvInvoiceTotal.setText(Utils.formatCurrencyAmount(this, data.getBill().getTotal()));

isPromoApplied = data.getBill().getPromo() != null;
mViewModel.setmIsPromoApplied(data.getBill().getPromo() != null);

setUpUi("Discount", false, R.drawable.bordered_text_light_grey, View.VISIBLE, View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.checkin.app.checkin.manager.fragments;


import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import butterknife.BindView
import butterknife.OnClick
import com.checkin.app.checkin.R
import com.checkin.app.checkin.data.resource.Resource
import com.checkin.app.checkin.manager.viewmodels.ManagerSessionViewModel
import com.checkin.app.checkin.misc.fragments.BaseBottomSheetFragment
import com.checkin.app.checkin.utility.Utils

class ManagerSessionPaymentOptionsBottomSheetFragment : BaseBottomSheetFragment() {
override val rootLayout: Int = R.layout.fragment_manager_session_payment_options

@BindView(R.id.tv_manager_session_payment_amount)
internal lateinit var tvManagerSessionAmount: TextView

private val viewModel: ManagerSessionViewModel by activityViewModels()

private val isPromoApplied by lazy {
viewModel.getmIsPromoApplied()
}

private val isRequestedCheckout by lazy {
viewModel.getmIsRequestedCheckout()
}

@OnClick(R.id.card_manager_session_payment_bhim, R.id.card_manager_session_payment_card, R.id.card_manager_session_payment_cash)
fun submitButton(v: View) {
when (v.id) {
R.id.card_manager_session_payment_bhim -> viewModel.setPaymentMode(ManagerSessionViewModel.PAYMENT_MODE.UPI)
R.id.card_manager_session_payment_card -> viewModel.setPaymentMode(ManagerSessionViewModel.PAYMENT_MODE.CARD)
R.id.card_manager_session_payment_cash -> viewModel.setPaymentMode(ManagerSessionViewModel.PAYMENT_MODE.CASH)
}

val builder = AlertDialog.Builder(requireContext()).setTitle("Are you sure you want to close session?")
.setNegativeButton("No") { dialog: DialogInterface, _: Int -> dialog.cancel() }
if (!isPromoApplied || isRequestedCheckout) builder.setPositiveButton("Close session") { _: DialogInterface, _: Int ->
viewModel.putSessionCheckout()
dialog?.dismiss()
dismiss()
} else builder.setPositiveButton("Notify waiter") { dialog: DialogInterface?, _: Int ->
viewModel.requestSessionCheckout()
dialog?.dismiss()
dismiss()
}
if (!isPromoApplied && !isRequestedCheckout)
builder.setNeutralButton("Notify waiter") { dialog: DialogInterface?, i: Int ->
viewModel.requestSessionCheckout()
dialog?.dismiss()
dismiss()

}
builder.show()
}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewModel.sessionInvoice.observe(viewLifecycleOwner, Observer { resource ->
if (resource == null) return@Observer
if (resource.status === Resource.Status.SUCCESS && resource.data != null) {
val total = resource.data.bill.total
tvManagerSessionAmount.text = Utils.formatCurrencyAmount(context, total)
}
})
}

companion object {
fun newInstance() = ManagerSessionPaymentOptionsBottomSheetFragment()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ManagerASLiveTablesViewModel(application: Application) : BaseViewModel(app
fun markSessionDone(sessionId: Long) {
val data = Converters.objectMapper.createObjectNode()
data.put("payment_mode", "csh")
mCheckoutData.addSource(mManagerRepository.manageSessionCheckout(sessionId), mCheckoutData::setValue)
mCheckoutData.addSource(mManagerRepository.manageSessionCheckout(sessionId, data), mCheckoutData::setValue)
}

fun fetchActiveTables(restaurantId: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class ManagerSessionViewModel extends BaseViewModel {
private boolean discountInINR;
private long mSessionPk;
private long mShopPk;
private PAYMENT_MODE mPaymentMode = PAYMENT_MODE.CASH;
private boolean mIsRequestedCheckout;
private boolean mIsPromoApplied;

public ManagerSessionViewModel(@NonNull Application application) {
super(application);
Expand All @@ -68,8 +71,8 @@ public ManagerSessionViewModel(@NonNull Application application) {

public void putSessionCheckout() {
ObjectNode data = Converters.INSTANCE.getObjectMapper().createObjectNode();
data.put("payment_mode", "csh");
mCheckoutData.addSource(mManagerRepository.manageSessionCheckout(mSessionPk), mCheckoutData::setValue);
data.put("payment_mode", mPaymentMode.tag);
mCheckoutData.addSource(mManagerRepository.manageSessionCheckout(mSessionPk, data), mCheckoutData::setValue);
}

public LiveData<Resource<CheckoutStatusModel>> getCheckoutData() {
Expand Down Expand Up @@ -112,7 +115,7 @@ public void updateDiscount(double value) {

public void requestSessionCheckout() {
ObjectNode data = Converters.INSTANCE.getObjectMapper().createObjectNode();
data.put("payment_mode", "csh");
data.put("payment_mode", mPaymentMode.tag);
mCheckoutData.addSource(mWaiterRepository.postSessionRequestCheckout(mSessionPk, data), mCheckoutData::setValue);
}

Expand Down Expand Up @@ -339,6 +342,10 @@ public void setShopPk(long shopId) {
mShopPk = shopId;
}

public void setPaymentMode(PAYMENT_MODE mode) {
mPaymentMode = mode;
}

public void markEventDone(long eventPk) {
mDetailData.addSource(mWaiterRepository.markEventDone(eventPk), mDetailData::setValue);
}
Expand Down Expand Up @@ -412,4 +419,30 @@ public void switchTable(long qrPk) {
public LiveData<Resource<ObjectNode>> getSessionSwitchTable() {
return mSwitchTableData;
}

public void setmIsRequestedCheckout(boolean mIsRequestedCheckout) {
this.mIsRequestedCheckout = mIsRequestedCheckout;
}

public boolean getmIsRequestedCheckout() {
return mIsRequestedCheckout;
}

public void setmIsPromoApplied(boolean mIsPromoApplied) {
this.mIsPromoApplied = mIsPromoApplied;
}

public boolean getmIsPromoApplied() {
return mIsPromoApplied;
}

public enum PAYMENT_MODE {
CASH("csh"), CARD("crd"), UPI("upi");

public String tag;

PAYMENT_MODE(String tag) {
this.tag = tag;
}
}
}
Loading

0 comments on commit 36ce54f

Please sign in to comment.