Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshs9 committed Dec 31, 2020
2 parents 0aa16c5 + dcc330d commit 325bbfd
Show file tree
Hide file tree
Showing 20 changed files with 622 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void getData() {
mPagerAdapter.setData(revenueModel);
tvFloatingCash.setText(Utils.formatCurrencyAmount(requireContext(), revenueModel.getFloatingCash()));
tvCancellationRate.setText(revenueModel.getCancellationRate());
mAdapter.setData(revenueModel.getTrendingOrders());
mAdapter.setData(revenueModel.getItemRevenues());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ShopInsightRevenueModel {
private long avgServingTime;

@JsonProperty("trending_orders")
private List<ManagerStatsModel.TrendingOrder> trendingOrders;
private List<ManagerStatsModel.ItemRevenue> itemRevenues;

@JsonProperty("floating_cash")
private double floatingCash;
Expand Down Expand Up @@ -63,8 +63,8 @@ public long getAvgServingTime() {
return avgServingTime;
}

public List<ManagerStatsModel.TrendingOrder> getTrendingOrders() {
return trendingOrders;
public List<ManagerStatsModel.ItemRevenue> getItemRevenues() {
return itemRevenues;
}

public double getFloatingCash() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,53 @@ class ShopInvoiceViewModel(application: Application) : BaseViewModel(application
private var mPrevStatsResults: LiveData<Resource<RestaurantAdminStatsModel>>? = null
private val mStatsResults = createNetworkLiveData<RestaurantAdminStatsModel>()

val restaurantSessions: LiveData<Resource<List<RestaurantSessionModel>>>
get() = mResults

val restaurantStats: LiveData<Resource<RestaurantAdminStatsModel>>
get() = mStatsResults
val restaurantSessions: LiveData<Resource<List<RestaurantSessionModel>>> = mResults
val restaurantStats: LiveData<Resource<RestaurantAdminStatsModel>> = mStatsResults

var doFetchStats: Boolean = false

fun fetchShopSessions(restaurantId: Long) {
fun fetchShopSessions(restaurantId: Long = mShopPk) {
this.mShopPk = restaurantId
mPrevResults = mShopInvoiceRepository.getRestaurantSessions(restaurantId)
mResults.addSource(mPrevResults!!) { mResults.value = it }
if (mPrevResults != null)
mResults.removeSource(mPrevResults!!)
mPrevResults = if (fromDate == null && toDate == null) mShopInvoiceRepository.getRestaurantSessions(restaurantId)
else mShopInvoiceRepository.getRestaurantSessions(restaurantId, fromDate, toDate)
mResults.addSource(mPrevResults!!, mResults::setValue)
}

fun fetchShopStats(restaurantId: Long) {
this.mShopPk = restaurantId
mPrevStatsResults = mShopInvoiceRepository.getRestaurantAdminStats(restaurantId)
mStatsResults.addSource(mPrevStatsResults!!) { mStatsResults.value = it }
}

fun setShopPk(restaurantId: Long) {
this.mShopPk = restaurantId
}

private fun filterRestaurantSessions(fromDate: String?, toDate: String?) {
if (mPrevResults != null)
mResults.removeSource(mPrevResults!!)
mPrevResults = mShopInvoiceRepository.getRestaurantSessions(mShopPk, fromDate, toDate)
mResults.addSource(mPrevResults!!) { mResults.value = it }
mStatsResults.addSource(mPrevStatsResults!!, mStatsResults::setValue)
}

private fun filterRestaurantStats(fromDate: String?, toDate: String?) {
if (mPrevStatsResults != null)
mStatsResults.removeSource(mPrevStatsResults!!)
mPrevStatsResults = mShopInvoiceRepository.getRestaurantAdminStats(mShopPk, fromDate, toDate)
mStatsResults.addSource(mPrevStatsResults!!) { mStatsResults.value = it }
mStatsResults.addSource(mPrevStatsResults!!, mStatsResults::setValue)
}

fun filterFrom(fromDate: String) {
@JvmOverloads
fun filterFrom(fromDate: String, doFetch: Boolean = true) {
this.fromDate = fromDate
filterRestaurantSessions(fromDate, toDate)
if (doFetchStats) filterRestaurantStats(fromDate, toDate)
if (doFetch) {
fetchShopSessions()
if (doFetchStats) filterRestaurantStats(fromDate, toDate)
}
}

fun filterTo(toDate: String) {
@JvmOverloads
fun filterTo(toDate: String, doFetch: Boolean = true) {
this.toDate = toDate
filterRestaurantSessions(fromDate, toDate)
if (doFetchStats) filterRestaurantStats(fromDate, toDate)
if (doFetch) {
fetchShopSessions()
if (doFetchStats) filterRestaurantStats(fromDate, toDate)
}
}

override fun updateResults() {
fetchShopSessions(mShopPk)
fetchShopSessions()
if (doFetchStats) fetchShopStats(mShopPk)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ interface WebApiService {
fun deleteRestaurantMember(@Path("shop_id") shopId: Long, @Path("user_id") userId: Long): Call<ObjectNode>

@GET("sessions/restaurants/{restaurant_id}/")
fun getRestaurantSessionsById(@Path("restaurant_id") restaurantId: Long, @Query("checked_in_after") checkedOutAfter: String?, @Query("checked_in_before") checkedOutBefore: String?): Call<List<RestaurantSessionModel>>
fun getRestaurantSessionsById(@Path("restaurant_id") restaurantId: Long, @Query("checked_out_after") checkedOutAfter: String?, @Query("checked_out_before") checkedOutBefore: String?): Call<List<RestaurantSessionModel>>

@GET("sessions/restaurants/{restaurant_id}/scheduled/")
fun getScheduledSessionsById(@Path("restaurant_id") restaurantId: Long): Call<List<ShopScheduledSessionModel>>

@GET("restaurants/{restaurant_id}/stats/admin")
fun getRestaurantAdminStats(@Path("restaurant_id") restaurantId: Long, @Query("checked_in_after") checkedOutAfter: String?, @Query("checked_in_before") checkedOutBefore: String?): Call<RestaurantAdminStatsModel>
fun getRestaurantAdminStats(@Path("restaurant_id") restaurantId: Long, @Query("checked_out_after") checkedOutAfter: String?, @Query("checked_out_before") checkedOutBefore: String?): Call<RestaurantAdminStatsModel>

@GET("sessions/manage/{session_id}/detail/")
fun getShopSessionDetailById(@Path("session_id") sessionId: Long): Call<ShopSessionDetailModel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ class ManagerWorkActivity : BaseAccountActivity(), LiveOrdersInteraction {

private fun setupObservers(shopId: Long) {
mViewModel.fetchRestaurantData(shopId)
Utils.getCurrentFormattedDateInvoice().also { currDate ->
mShopViewModel.filterFrom(currDate, doFetch = false)
mShopViewModel.filterTo(currDate, doFetch = false)
}
mShopViewModel.fetchShopSessions(shopId)
mShopViewModel.filterFrom(Utils.getCurrentFormattedDateInvoice())
mShopViewModel.filterTo(Utils.getCurrentFormattedDateInvoice())
}

override fun setLiveOrdersActivation(isActivated: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@

public class ManagerStatsOrderAdapter extends RecyclerView.Adapter<ManagerStatsOrderAdapter.ShopManagerTableStaticsHolder> {

private List<ManagerStatsModel.TrendingOrder> mData;
private List<ManagerStatsModel.ItemRevenue> mData;

public ManagerStatsOrderAdapter() {
}

public void setData(List<ManagerStatsModel.TrendingOrder> trendingOrder) {
this.mData = trendingOrder;
public void setData(List<ManagerStatsModel.ItemRevenue> itemRevenue) {
this.mData = itemRevenue;
notifyDataSetChanged();
}

@NonNull
@Override
public ShopManagerTableStaticsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_shop_manager_stats_order, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_menu_analysis_item_revenue, parent, false);
return new ShopManagerTableStaticsHolder(view);
}

Expand Down Expand Up @@ -62,7 +62,7 @@ static class ShopManagerTableStaticsHolder extends RecyclerView.ViewHolder {
ButterKnife.bind(this, itemView);
}

public void bindData(ManagerStatsModel.TrendingOrder data) {
public void bindData(ManagerStatsModel.ItemRevenue data) {
MenuItemBriefModel item = data.getItem();
double revenueGenerated = data.getRevenueContribution();
if (item != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class ManagerInvoiceFragment : BaseFragment(), ShopInvoiceInteraction {
@BindView(R.id.rv_shop_invoice_sessions)
internal lateinit var rvSessions: RecyclerView


private val mAdapter: ShopInvoiceSessionAdapter by lazy {
ShopInvoiceSessionAdapter(this)
}
private val mViewModel: ShopInvoiceViewModel by activityViewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initRefreshScreen(R.id.sr_manager_invoice)
setupUi()
Expand All @@ -49,9 +49,11 @@ class ManagerInvoiceFragment : BaseFragment(), ShopInvoiceInteraction {

override fun updateScreen() {
super.updateScreen()
mViewModel.filterFrom(Utils.getCurrentFormattedDateInvoice())
mViewModel.filterTo(Utils.getCurrentFormattedDateInvoice())
mViewModel.updateResults()
Utils.getCurrentFormattedDateInvoice().also { currDate ->
mViewModel.filterFrom(currDate, doFetch = false)
mViewModel.filterTo(currDate, doFetch = false)
}
mViewModel.fetchShopSessions()
}

override fun onClickSession(data: RestaurantSessionModel?) {
Expand All @@ -65,4 +67,4 @@ class ManagerInvoiceFragment : BaseFragment(), ShopInvoiceInteraction {
companion object {
fun newInstance() = ManagerInvoiceFragment()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,132 @@ import android.view.View
import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import com.airbnb.epoxy.EpoxyRecyclerView
import com.checkin.app.checkin.R
import com.checkin.app.checkin.data.resource.Resource
import com.checkin.app.checkin.manager.adapters.ManagerStatsOrderAdapter
import com.checkin.app.checkin.manager.holders.statsMenuAnalysisGroupRevenue
import com.checkin.app.checkin.manager.holders.statsMenuAnalysisItemRevenue
import com.checkin.app.checkin.manager.models.ManagerStatsModel
import com.checkin.app.checkin.manager.viewmodels.ManagerWorkViewModel
import com.checkin.app.checkin.misc.fragments.BaseFragment
import com.checkin.app.checkin.misc.holders.textSectionModelHolder
import com.checkin.app.checkin.utility.Utils
import java.util.*
import com.checkin.app.checkin.utility.isNotEmpty

class ManagerStatsFragment : BaseFragment() {
override val rootLayout: Int = R.layout.fragment_shop_manager_statistics

@BindView(R.id.rv_manager_stats_trending_orders)
internal lateinit var rvTrendingOrders: RecyclerView
@BindView(R.id.tv_manager_stats_revenue_day)
@BindView(R.id.epoxy_rv_manager_stats_menu_analysis)
internal lateinit var epoxyRvMenuAnalysis: EpoxyRecyclerView

@BindView(R.id.tv_manager_stats_revenue_live)
internal lateinit var tvLiveCartRevenue: TextView

@BindView(R.id.tv_manager_stats_revenue_yesterday)
internal lateinit var tvYesterdayRevenue: TextView

@BindView(R.id.tv_manager_stats_revenue_today)
internal lateinit var tvDayRevenue: TextView

@BindView(R.id.tv_manager_stats_revenue_week)
internal lateinit var tvWeekRevenue: TextView
@BindView(R.id.tv_manager_stats_orders_day)

@BindView(R.id.tv_manager_stats_orders_live)
internal lateinit var tvLiveCartOrders: TextView

@BindView(R.id.tv_manager_stats_orders_yesterday)
internal lateinit var tvYesterdayOrders: TextView

@BindView(R.id.tv_manager_stats_orders_today)
internal lateinit var tvDayOrders: TextView

@BindView(R.id.tv_manager_stats_orders_week)
internal lateinit var tvWeekOrders: TextView
@BindView(R.id.tv_manager_stats_session_time)

@BindView(R.id.tv_manager_analysis_acceptance_time)
internal lateinit var tvOrderAcceptanceTime: TextView

@BindView(R.id.tv_manager_analysis_session_time)
internal lateinit var tvSessionTime: TextView
@BindView(R.id.tv_manager_stats_serving_time)

@BindView(R.id.tv_manager_analysis_serving_time)
internal lateinit var tvServingTime: TextView

private val mAdapter: ManagerStatsOrderAdapter by lazy { ManagerStatsOrderAdapter() }
private val mViewModel: ManagerWorkViewModel by activityViewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initRefreshScreen(R.id.sr_manager_stats)
rvTrendingOrders.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
rvTrendingOrders.adapter = mAdapter
epoxyRvMenuAnalysis.withModels {
mViewModel.restaurantStatistics.value?.data?.trendingItems.takeIf { it.isNotEmpty() }?.also {
textSectionModelHolder {
withRedSmallLayout()
id("trending_items")
heading("TRENDING ITEMS IN LAST 30 DAYS")
}
it.forEachIndexed { idx, data ->
statsMenuAnalysisItemRevenue {
id("trending_items.$idx")
data(data)
}
}
}

mViewModel.restaurantStatistics.value?.data?.poorItems.takeIf { it.isNotEmpty() }?.also {
textSectionModelHolder {
withRedSmallLayout()
id("poor_items")
heading("LEAST SELLING ITEM IN LAST 30 DAYS")
}
it.forEachIndexed { idx, data ->
statsMenuAnalysisItemRevenue {
id("poor_items.$idx")
data(data)
}
}
}

mViewModel.restaurantStatistics.value?.data?.trendingGroups.takeIf { it.isNotEmpty() }?.also {
textSectionModelHolder {
withRedSmallLayout()
id("trending_groups")
heading("TOP GROUP IN LAST 30 DAYS")
}
it.forEachIndexed { idx, data ->
statsMenuAnalysisGroupRevenue {
id("trending_groups.$idx")
index(idx + 1)
data(data)
}
}
}
}

mViewModel.fetchStatistics()
mViewModel.restaurantStatistics.observe(this, Observer {
mViewModel.restaurantStatistics.observe(viewLifecycleOwner, Observer {
it?.let { input ->
handleLoadingRefresh(input)
if (input.status === Resource.Status.SUCCESS && input.data != null) {
setupData(input.data)
epoxyRvMenuAnalysis.requestModelBuild()
}
}
})
}

private fun setupData(data: ManagerStatsModel) {
tvDayOrders.text = String.format(Locale.ENGLISH, "%s orders", data.dayOrdersCount)
tvWeekOrders.text = String.format(Locale.ENGLISH, "%s orders", data.weekOrdersCount)
tvDayRevenue.text = Utils.formatCurrencyAmount(context, data.dayRevenue)
tvWeekRevenue.text = Utils.formatCurrencyAmount(context, data.weekRevenue)
tvSessionTime.text = data.formatAvgSessionTime()
tvServingTime.text = data.formatAvgServingTime()
mAdapter.setData(data.trendingOrders)
tvLiveCartOrders.text = "%.0f Orders".format(data.countOrders.live)
tvDayOrders.text = "%.0f Orders".format(data.countOrders.day)
tvYesterdayOrders.text = "%.0f Orders".format(data.countOrders.yesterday)
tvWeekOrders.text = "%.0f Orders".format(data.countOrders.week)
tvLiveCartRevenue.text = Utils.formatCurrencyAmount(context, data.revenue.live)
tvDayRevenue.text = Utils.formatCurrencyAmount(context, data.revenue.day)
tvYesterdayRevenue.text = Utils.formatCurrencyAmount(context, data.revenue.yesterday)
tvWeekRevenue.text = Utils.formatCurrencyAmount(context, data.revenue.week)

tvSessionTime.text = "%s Session time".format(data.formatAvgSessionTime())
tvServingTime.text = "%s Serving time".format(data.formatAvgServingTime())
tvOrderAcceptanceTime.text = "%s Order Accepting time".format(data.formatOrderAcceptingTime())
}

override fun updateScreen() {
Expand Down
Loading

0 comments on commit 325bbfd

Please sign in to comment.