Advertisement
stevekamau

Untitled

Oct 23rd, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 47.33 KB | None | 0 0
  1. package com.duka.activities;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.graphics.Color;
  6. import android.net.ConnectivityManager;
  7. import android.net.NetworkInfo;
  8. import android.os.AsyncTask;
  9. import android.os.Bundle;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.support.v7.widget.Toolbar;
  12. import android.util.Log;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.widget.AdapterView;
  16. import android.widget.ArrayAdapter;
  17. import android.widget.RadioButton;
  18. import android.widget.RelativeLayout;
  19. import android.widget.Spinner;
  20. import android.widget.TextView;
  21.  
  22. import com.duka.R;
  23. import com.github.mikephil.charting.charts.LineChart;
  24. import com.github.mikephil.charting.charts.PieChart;
  25. import com.github.mikephil.charting.components.Legend;
  26. import com.github.mikephil.charting.components.XAxis;
  27. import com.github.mikephil.charting.data.Entry;
  28. import com.github.mikephil.charting.data.LineData;
  29. import com.github.mikephil.charting.data.LineDataSet;
  30. import com.github.mikephil.charting.data.PieData;
  31. import com.github.mikephil.charting.data.PieDataSet;
  32. import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
  33. import com.github.mikephil.charting.utils.ColorTemplate;
  34. import com.loopj.android.http.AsyncHttpClient;
  35. import com.loopj.android.http.AsyncHttpResponseHandler;
  36. import com.loopj.android.http.RequestParams;
  37.  
  38. import org.json.JSONArray;
  39. import org.json.JSONException;
  40. import org.json.JSONObject;
  41.  
  42. import java.text.DateFormat;
  43. import java.text.ParseException;
  44. import java.text.SimpleDateFormat;
  45. import java.util.ArrayList;
  46. import java.util.Calendar;
  47. import java.util.Collections;
  48. import java.util.Comparator;
  49. import java.util.Date;
  50. import java.util.HashMap;
  51. import java.util.List;
  52. import java.util.Locale;
  53.  
  54. import butterknife.BindView;
  55. import butterknife.ButterKnife;
  56. import cz.msebera.android.httpclient.Header;
  57. import dataBaseHandlers.SalesHandler;
  58. import fr.castorflex.android.smoothprogressbar.SmoothProgressBar;
  59. import utility.AccountSharedPreferences;
  60. import utility.Crouton;
  61. import utility.CustomMarkerView;
  62. import utility.CustomValueFormatter;
  63. import utility.PercentagesValueFormatter;
  64. import utility.PeriodHelper;
  65. import utility.Style;
  66.  
  67. public class Reports extends AppCompatActivity {
  68.     SalesHandler sh;
  69.     @BindView(R.id.app_bar)
  70.     Toolbar toolbar;
  71.     @BindView(R.id.hour_radioBtn)
  72.     RadioButton hourButton;
  73.     @BindView(R.id.day_radioBtn)
  74.     RadioButton dayButton;
  75.     @BindView(R.id.month_radioBtn)
  76.     RadioButton monthButton;
  77.     @BindView(R.id.for_1)
  78.     Spinner year_spinner;
  79.     @BindView(R.id.for_2)
  80.     Spinner day_spinner;
  81.     @BindView(R.id.for_3)
  82.     Spinner month_spinner;
  83.     @BindView(R.id.spinner_lay1)
  84.     RelativeLayout layout1;
  85.     @BindView(R.id.spinner_lay2)
  86.     RelativeLayout layout2;
  87.     @BindView(R.id.spinner_lay3)
  88.     RelativeLayout layout3;
  89.     @BindView(R.id.prog1)
  90.     SmoothProgressBar progressBar;
  91.     @BindView(R.id.expenses_line_graph)
  92.     LineChart expensesLineChart;
  93.     @BindView(R.id.linegraph)
  94.     LineChart salesLineChart;
  95.     @BindView(R.id.x_title)
  96.     TextView salesXTitle;
  97.     @BindView(R.id.tvContent)
  98.     TextView tvContent;
  99.     @BindView(R.id.product_pie_chart)
  100.     PieChart product_pieChart;
  101.     @BindView(R.id.customer_pie_chart)
  102.     PieChart customer_pieChart;
  103.     @BindView(R.id.staff_pie_chart)
  104.     PieChart staff_pieChart;
  105.     String date, final_month;
  106.     int yearCheck = 0;
  107.     int monthCheck = 0;
  108.     int dayCheck = 0;
  109.     AccountSharedPreferences asp;
  110.     String[] day_spinner_array;
  111.     String[] month_spinner_array;
  112.     Boolean isYear = true;
  113.     Boolean isDay = true;
  114.     Boolean isMonth = true;
  115.     PeriodHelper monthPosition;
  116.     AsyncHttpClient client;
  117.  
  118.     public static JSONArray getSortedListByDate(JSONArray array) throws JSONException {
  119.         List<JSONObject> list = new ArrayList<JSONObject>();
  120.         for (int i = 0; i < array.length(); i++) {
  121.             list.add(0, array.getJSONObject(i));
  122.         }
  123.         Collections.sort(list, new SortBasedOnCreatedAt());
  124.  
  125.         JSONArray resultArray = new JSONArray(list);
  126.  
  127.         return resultArray;
  128.     }
  129.  
  130.     @Override
  131.     protected void onCreate(Bundle savedInstanceState) {
  132.         super.onCreate(savedInstanceState);
  133.         setContentView(R.layout.activity_reports);
  134.         ButterKnife.bind(this);
  135.  
  136.         setSupportActionBar(toolbar);
  137.         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  138.         getSupportActionBar().setTitle("Reports");
  139.         toolbar.setNavigationIcon(com.duka.R.drawable.menu);
  140.         sh = new SalesHandler(getApplicationContext());
  141. //        sh.getSumOfGroupedTime();
  142.         asp = new AccountSharedPreferences(this);
  143.         monthPosition = new PeriodHelper();
  144.         client = new AsyncHttpClient();
  145.         createViews();
  146.  
  147.     }
  148.  
  149.     private void createViews() {
  150.         setUpSpinners();
  151.       /*  sh.values();
  152.         sh.hour_labels();*/
  153.         //initialize MPChart
  154.        /* ArrayList<String> hour_labels = new ArrayList<String>();
  155.         ArrayList<Entry> values = new ArrayList<>();
  156.         values.add(new Entry(5, 0));
  157.         values.add(new Entry(2, 1));
  158.         hour_labels.add(0, "Test1");
  159.         hour_labels.add(0, "Test2");*/
  160.         initializeSalesMPChart(sh.sales_values(), sh.hour_labels(), "hours");
  161.         initializeProductPieChart(sh.products_values(), sh.product_labels());
  162.         initializeCustomerPieChart(sh.customer_values(), sh.customer_labels());
  163.         initializeStaffPieChart(sh.staff_values(), sh.staff_labels());
  164. //        initializeExpensesMPChart(sh.values(), sh.hour_labels());
  165.     }
  166.  
  167.     private void initializeSalesMPChart(ArrayList<Entry> values, ArrayList<String> labels, String period) {
  168.  
  169.         Log.d("report_api_", "api_request displaying in chart");
  170.         CustomMarkerView mv = new CustomMarkerView(getApplicationContext(),
  171.                 R.layout.custom_marker_view_layout, "sales", labels, period);
  172.         // set the marker to the chart
  173.         salesLineChart.setMarkerView(mv);
  174. //        mpChart.setOnChartGestureListener(this);
  175. //        mpChart.setOnChartValueSelectedListener(this);
  176.         // ArrayList<Entry> values = new ArrayList<>();
  177.  
  178.         //x,y
  179.        /* values.add(new Entry(5, 10));
  180.         values.add(new Entry(2, 4));
  181.         values.add(new Entry(6, 10));
  182.         values.add(new Entry(3, 1));
  183.         values.add(new Entry(6, 10));
  184.         values.add(new Entry(7, 13));
  185.         values.add(new Entry(9, 7));*/
  186.  
  187.         LineDataSet report = new LineDataSet(values, "Records");
  188.         /*report.setAxisDependency(YAxis.AxisDependency.LEFT);
  189.         report.setColor(getResources().getColor(R.color.green_color));
  190.         report.setCircleColor(Color.RED);
  191.         report.setCircleColorHole(Color.RED);
  192.         report.setCircleRadius(2f);
  193.         report.setHighLightColor(Color.parseColor("#448AFF"));*/
  194.         report.setColor(Color.parseColor("#758cbb"));
  195. //        report.setColor(getResources().getColor(R.color.green_color));
  196. //        report.setCircleColor(Color.BLACK);
  197.         report.setCircleColor(Color.parseColor("#ffc755"));
  198.         report.setLineWidth(3f);
  199.         report.setCircleSize(3f);
  200. //        report.setFillAlpha(10);
  201.         report.setFillColor(Color.parseColor("#2d374c"));
  202. //        report.setDrawCircles(true);
  203. //        report.setValueTextSize(-5f);
  204.         report.setValueTextSize(0f);
  205.  
  206.         ArrayList<ILineDataSet> dataSets = new ArrayList<>();
  207.         dataSets.add(report);
  208.  
  209.         LineData data = new LineData(labels, dataSets);
  210.         data.setValueFormatter(new CustomValueFormatter());
  211.         XAxis xAxis = salesLineChart.getXAxis();
  212.         xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
  213.         xAxis.setTextSize(10f);
  214.         xAxis.setDrawAxisLine(true);
  215.         xAxis.setDrawGridLines(false);
  216.         xAxis.setTextSize(9);
  217. //        if (period.equals("hours")) {
  218. //
  219. //        }
  220. //        if (period.equals("days")) {
  221. //            xAxis.setLabelsToSkip(1);
  222. //        }
  223. //        if (period.equals("months")) {
  224. //
  225. //        }
  226.  
  227.  
  228.         Legend l = salesLineChart.getLegend();
  229.         l.setEnabled(false);
  230.         //indicates if auto scaling on the y axis is enabled
  231.         // salesLineChart.setAutoScaleMinMaxEnabled(true);
  232.         salesLineChart.setDescription("");
  233.         // if disabled, scaling can be done on x- and y-axis separately
  234.         salesLineChart.setPinchZoom(true);
  235.         salesLineChart.setDrawBorders(false);
  236.         /*
  237.         salesLineChart.setVisibleXRangeMinimum(4);*/
  238.         salesLineChart.setBorderColor(getResources().getColor(R.color.grey));
  239.         salesLineChart.setScaleEnabled(true);
  240.         salesLineChart.setTouchEnabled(true);
  241.         salesLineChart.setDragEnabled(true);
  242.         salesLineChart.setDoubleTapToZoomEnabled(false);
  243.         salesLineChart.getAxisLeft().setEnabled(true);
  244.         salesLineChart.getAxisLeft().setTextColor(Color.parseColor("#6a84c3"));
  245.         salesLineChart.getAxisRight().setEnabled(false);
  246.         salesLineChart.getXAxis().setEnabled(true);
  247.         salesLineChart.getXAxis().setTextColor(Color.parseColor("#6a84c3"));
  248.         salesLineChart.animateXY(2000, 2000);
  249.         salesLineChart.setNoDataTextDescription("No data available");
  250.         //salesLineChart.invalidate();
  251.         salesLineChart.notifyDataSetChanged();
  252.  
  253.         salesLineChart.invalidate();
  254.  
  255.         salesLineChart.setData(data);
  256.  
  257.         Log.d("array_report", "done setting sales to graph");
  258.     }
  259.  
  260.     private void initializeExpensesMPChart(ArrayList<Entry> values, ArrayList<String> labels) {
  261.  
  262.         LineDataSet report = new LineDataSet(values, "Records");
  263.         report.setColor(Color.parseColor("#758cbb"));
  264.         report.setCircleColor(Color.parseColor("#ffc755"));
  265.         report.setLineWidth(3f);
  266.         report.setCircleSize(3f);
  267.         report.setFillColor(Color.parseColor("#2d374c"));
  268.         report.setValueTextSize(0f);
  269.  
  270.         ArrayList<ILineDataSet> dataSets = new ArrayList<>();
  271.         dataSets.add(report);
  272.  
  273.         LineData data = new LineData(labels, dataSets);
  274.  
  275.         XAxis xAxis = expensesLineChart.getXAxis();
  276.         xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
  277.         xAxis.setTextSize(10f);
  278.         xAxis.setDrawAxisLine(true);
  279.         xAxis.setDrawGridLines(false);
  280.         data.setValueFormatter(new CustomValueFormatter());
  281.  
  282.  
  283.         Legend l = expensesLineChart.getLegend();
  284.         l.setEnabled(false);
  285.         expensesLineChart.setDescription("");
  286.         // if disabled, scaling can be done on x- and y-axis separately
  287.         expensesLineChart.setPinchZoom(true);
  288.         expensesLineChart.setDrawBorders(false);
  289.         /*
  290.         salesLineChart.setVisibleXRangeMinimum(4);*/
  291.         expensesLineChart.setBorderColor(getResources().getColor(R.color.grey));
  292.         expensesLineChart.setScaleEnabled(true);
  293.         expensesLineChart.setTouchEnabled(true);
  294.         expensesLineChart.setDragEnabled(true);
  295.         expensesLineChart.setDoubleTapToZoomEnabled(false);
  296.         expensesLineChart.getAxisLeft().setEnabled(true);
  297.         expensesLineChart.getAxisLeft().setTextColor(Color.parseColor("#6a84c3"));
  298.         expensesLineChart.getAxisRight().setEnabled(false);
  299.         expensesLineChart.getXAxis().setEnabled(true);
  300.         expensesLineChart.getXAxis().setTextColor(Color.parseColor("#6a84c3"));
  301.         expensesLineChart.animateXY(2000, 2000);
  302.         expensesLineChart.setNoDataTextDescription("No data available");
  303.         //salesLineChart.invalidate();
  304.         expensesLineChart.notifyDataSetChanged();
  305.  
  306.         expensesLineChart.invalidate();
  307.  
  308.         expensesLineChart.setData(data);
  309.     }
  310.  
  311.     private void initializeProductPieChart(ArrayList<Entry> p_entries, ArrayList<String> product_labels) {
  312.        /* ArrayList<Entry> entries = new ArrayList<>();
  313.         entries.add(new Entry(4f, 0));
  314.         entries.add(new Entry(8f, 1));
  315.         entries.add(new Entry(6f, 2));
  316.         entries.add(new Entry(12f, 3));
  317.         entries.add(new Entry(18f, 4));
  318.         entries.add(new Entry(9f, 5));*/
  319.  
  320.         PieDataSet dataset = new PieDataSet(p_entries, "");
  321.  
  322.       /*  ArrayList<String> labels = new ArrayList<String>();
  323.         labels.add("January");
  324.         labels.add("February");
  325.         labels.add("March");
  326.         labels.add("April");
  327.         labels.add("May");
  328.         labels.add("June");*/
  329.         Legend l = product_pieChart.getLegend();
  330.         product_pieChart.getLegend().setWordWrapEnabled(true);
  331.         l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
  332.         l.setXEntrySpace(7f);
  333.         l.setYEntrySpace(0f);
  334.         l.setYOffset(0f);
  335.  
  336.         PieData data = new PieData(product_labels, dataset);
  337.  
  338.         // add a lot of colors
  339.         ArrayList<Integer> colors = new ArrayList<Integer>();
  340.  
  341.         for (int c : ColorTemplate.VORDIPLOM_COLORS)
  342.             colors.add(c);
  343.         for (int c : ColorTemplate.PASTEL_COLORS)
  344.             colors.add(c);
  345.         for (int c : ColorTemplate.COLORFUL_COLORS)
  346.             colors.add(c);
  347.         for (int c : ColorTemplate.JOYFUL_COLORS)
  348.             colors.add(c);
  349.         for (int c : ColorTemplate.LIBERTY_COLORS)
  350.             colors.add(c);
  351.  
  352.         colors.add(ColorTemplate.getHoloBlue());
  353.  
  354.         dataset.setColors(colors);
  355. //        data.setValueTextSize(0);
  356. //        dataset.setColors(getResources().getIntArray(R.array.androidcolors));
  357.         dataset.setSliceSpace(0);
  358.         data.setValueFormatter(new PercentagesValueFormatter());
  359.         product_pieChart.setDragDecelerationFrictionCoef(0.95f);
  360.         product_pieChart.setDescription("");
  361.         product_pieChart.setUsePercentValues(true);
  362.         product_pieChart.setData(data);
  363.         product_pieChart.animateY(2000);
  364.         product_pieChart.setDescriptionTextSize(0);
  365.         product_pieChart.setDrawSliceText(false);
  366.  
  367.     }
  368.  
  369.     private void initializeCustomerPieChart(ArrayList<Entry> c_entries, ArrayList<String> customer_labels) {
  370.         PieDataSet dataset = new PieDataSet(c_entries, "");
  371.  
  372.       /*  ArrayList<String> labels = new ArrayList<String>();
  373.         labels.add("January");
  374.         labels.add("February");
  375.         labels.add("March");
  376.         labels.add("April");
  377.         labels.add("May");
  378.         labels.add("June");*/
  379.         Legend l = customer_pieChart.getLegend();
  380.         customer_pieChart.getLegend().setWordWrapEnabled(true);
  381.         l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
  382.         l.setXEntrySpace(7f);
  383.         l.setYEntrySpace(0f);
  384.         l.setYOffset(0f);
  385.  
  386.         PieData data = new PieData(customer_labels, dataset);
  387.         // add a lot of colors
  388.         ArrayList<Integer> colors = new ArrayList<Integer>();
  389.  
  390.         for (int c : ColorTemplate.VORDIPLOM_COLORS)
  391.             colors.add(c);
  392.         for (int c : ColorTemplate.PASTEL_COLORS)
  393.             colors.add(c);
  394.         for (int c : ColorTemplate.COLORFUL_COLORS)
  395.             colors.add(c);
  396.         for (int c : ColorTemplate.JOYFUL_COLORS)
  397.             colors.add(c);
  398.         for (int c : ColorTemplate.LIBERTY_COLORS)
  399.             colors.add(c);
  400.  
  401.         colors.add(ColorTemplate.getHoloBlue());
  402.  
  403.         colors.add(ColorTemplate.getHoloBlue());
  404.  
  405.         data.setValueFormatter(new PercentagesValueFormatter());
  406.         dataset.setColors(colors);
  407. //        dataset.setColors(getResources().getIntArray(R.array.androidcolors));
  408. //        dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
  409.         customer_pieChart.setDescription("");
  410.         customer_pieChart.setDragDecelerationFrictionCoef(0.95f);
  411.         customer_pieChart.setDescription("");
  412.         customer_pieChart.setUsePercentValues(true);
  413.         customer_pieChart.setData(data);
  414.         customer_pieChart.setDescriptionTextSize(0);
  415.         customer_pieChart.setDrawSliceText(false);
  416.         customer_pieChart.animateY(2000);
  417.     }
  418.  
  419.     private void initializeStaffPieChart(ArrayList<Entry> entries, ArrayList<String> staff_labels) {
  420.         PieDataSet dataset = new PieDataSet(entries, "");
  421.         Legend l = staff_pieChart.getLegend();
  422.         staff_pieChart.getLegend().setWordWrapEnabled(true);
  423.         l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
  424.         l.setXEntrySpace(7f);
  425.         l.setYEntrySpace(0f);
  426.         l.setYOffset(0f);
  427.  
  428.         PieData data = new PieData(staff_labels, dataset);
  429.         // add a lot of colors
  430.         ArrayList<Integer> colors = new ArrayList<Integer>();
  431.  
  432.         for (int c : ColorTemplate.VORDIPLOM_COLORS)
  433.             colors.add(c);
  434.         for (int c : ColorTemplate.PASTEL_COLORS)
  435.             colors.add(c);
  436.         for (int c : ColorTemplate.COLORFUL_COLORS)
  437.             colors.add(c);
  438.         for (int c : ColorTemplate.JOYFUL_COLORS)
  439.             colors.add(c);
  440.         for (int c : ColorTemplate.LIBERTY_COLORS)
  441.             colors.add(c);
  442.  
  443.         colors.add(ColorTemplate.getHoloBlue());
  444.  
  445.         colors.add(ColorTemplate.getHoloBlue());
  446.  
  447.         data.setValueFormatter(new PercentagesValueFormatter());
  448.         dataset.setColors(colors);
  449. //        dataset.setColors(getResources().getIntArray(R.array.androidcolors));
  450. //        dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
  451.         staff_pieChart.setDescription("");
  452.         staff_pieChart.setDragDecelerationFrictionCoef(0.95f);
  453.         staff_pieChart.setDescription("");
  454.         staff_pieChart.setUsePercentValues(true);
  455.         staff_pieChart.setData(data);
  456.         staff_pieChart.setDescriptionTextSize(0);
  457.         staff_pieChart.setDrawSliceText(false);
  458.         staff_pieChart.animateY(2000);
  459.     }
  460.  
  461.     private void setUpSpinners() {
  462.         //for year spinner
  463.         yearSpinner();
  464.         //for month spinner
  465.         monthSpinner();
  466.         //for day spinner
  467.         daySpinner(true);
  468.  
  469.     }
  470.  
  471.     private void yearSpinner() {
  472.         List<String> year_spinner_array = new ArrayList<>();
  473.         Calendar c3 = Calendar.getInstance();
  474.         c3.add(Calendar.MONTH, -1);
  475.         c3.add(Calendar.DAY_OF_MONTH, -1);
  476.         SimpleDateFormat mFormat3 = new SimpleDateFormat("yyyy", Locale.US);
  477.         int year = Integer.parseInt(mFormat3.format(c3.getTime()));
  478.         year_spinner_array.add(0, String.valueOf(year - 4));
  479.         year_spinner_array.add(0, String.valueOf(year - 3));
  480.         year_spinner_array.add(0, String.valueOf(year - 2));
  481.         year_spinner_array.add(0, String.valueOf(year - 1));
  482.         year_spinner_array.add(0, String.valueOf(year));
  483.  
  484.         ArrayAdapter<String> spinnerArrayAdapter3 = new ArrayAdapter<String>(this,
  485.                 R.layout.period_spinner_item, year_spinner_array);
  486.         //selected item will look like a spinner set from XML
  487.         spinnerArrayAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  488.         year_spinner.setAdapter(spinnerArrayAdapter3);
  489.         year_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  490.             @Override
  491.             public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
  492.                 yearCheck = yearCheck + 1;
  493.                 if (yearCheck > 1) {
  494. //                    date = (String) adapterView.getItemAtPosition(i);
  495.                     if (isMonth && isYear) {
  496.                         if (isDay) {
  497.                             date = year_spinner.getSelectedItem() + "/"
  498.                                     + month_spinner.getItemAtPosition(i) + "/"
  499.                                     + day_spinner.getSelectedItem();
  500.                             getDataFrom(date, "months");
  501. //                            Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  502.                         } else {
  503.                             date = (String) adapterView.getItemAtPosition(i) + "/"
  504.                                     + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem());
  505.                             getDataFrom(date, "months");
  506. //                            Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  507.                         }
  508.  
  509.                     } else {
  510.                         date = (String) adapterView.getItemAtPosition(i);
  511.                         getDataFrom(date, "months");
  512. //                        Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  513.                     }
  514.                 }
  515.  
  516.             }
  517.  
  518.             @Override
  519.             public void onNothingSelected(AdapterView<?> adapterView) {
  520.  
  521.             }
  522.         });
  523.     }
  524.  
  525.     private void monthSpinner() {
  526.        /* List<String> month_spinner_array = new ArrayList<>();
  527.         Calendar c2 = Calendar.getInstance();
  528.         c2.add(Calendar.MONTH, -1);
  529.         c2.add(Calendar.DAY_OF_MONTH, -1);
  530.         SimpleDateFormat mFormat2 = new SimpleDateFormat("MM", Locale.US);
  531.         while (c2.before(Calendar.getInstance())) {
  532.             month_spinner_array.add(0, mFormat2.format(c2.getTime()));
  533.             c2.add(Calendar.DAY_OF_MONTH, 1);
  534.         }
  535. */
  536.         Calendar c2 = Calendar.getInstance();
  537.         c2.add(Calendar.MONTH, 0);
  538.         c2.add(Calendar.DAY_OF_MONTH, 0);
  539.         SimpleDateFormat mFormat2 = new SimpleDateFormat("MMMM", Locale.US);
  540.         String month = mFormat2.format(c2.getTime());
  541.  
  542.         if (month.startsWith("0")) {
  543.             final_month = mFormat2.format(c2.getTime()).replace("0", "");
  544.         } else {
  545.             final_month = mFormat2.format(c2.getTime());
  546.         }
  547.  
  548.         month_spinner_array = getResources().getStringArray(R.array.month_name_arrays);
  549.         ArrayAdapter<String> spinnerArrayAdapter2 = new ArrayAdapter<String>(this,
  550.                 R.layout.period_spinner_item, month_spinner_array);
  551.         //selected item will look like a spinner set from XML
  552.         spinnerArrayAdapter2.setDropDownViewResource(R.layout.period_spinner_dropdown_item);
  553.         month_spinner.setAdapter(spinnerArrayAdapter2);
  554.         month_spinner.setSelection(((ArrayAdapter) month_spinner.getAdapter()).getPosition(month));
  555.         month_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  556.             @Override
  557.             public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
  558.                 monthCheck = monthCheck + 1;
  559.                 if (monthCheck > 1) {
  560. //                    date = (String) adapterView.getItemAtPosition(i);
  561. //                    daySpinner(false);
  562.                     if (isMonth && isYear) {
  563.                         if (isDay) {
  564.                             date = year_spinner.getSelectedItem() + "/"
  565.                                     + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()) + "/"
  566.                                     + day_spinner.getSelectedItem();
  567.                             getDataFrom(date, "days");
  568. //                            Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  569.                         } else {
  570.                             date = year_spinner.getSelectedItem() + "/"
  571.                                     + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem());
  572.                             getDataFrom(date, "days");
  573. //                            Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  574.                         }
  575.  
  576.                     }
  577.  
  578.                 }
  579.             }
  580.  
  581.             @Override
  582.             public void onNothingSelected(AdapterView<?> adapterView) {
  583.  
  584.             }
  585.         });
  586.     }
  587.  
  588.     private void daySpinner(final boolean b) {
  589.  
  590.         Calendar c = Calendar.getInstance();
  591.         c.add(Calendar.MONTH, -1);
  592.         c.add(Calendar.DAY_OF_MONTH, 0);
  593.         SimpleDateFormat mFormat = new SimpleDateFormat("dd", Locale.US);
  594. //        while (c.before(Calendar.getInstance())) {
  595. ////            day_spinner_array.add(0, mFormat.format(c.getTime()));
  596. //            c.add(Calendar.DAY_OF_MONTH, 1);
  597. //        }
  598.         String today = mFormat.format(c.getTime());
  599.  
  600. //        if () {
  601. //            day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  602. //        }
  603.  
  604.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("1")) {
  605.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  606.         }
  607.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("2")) {
  608.             day_spinner_array = getResources().getStringArray(R.array.days_28_arrays);
  609.         }
  610.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("3")) {
  611.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  612.         }
  613.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("4")) {
  614.             day_spinner_array = getResources().getStringArray(R.array.days_30_arrays);
  615.         }
  616.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("5")) {
  617.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  618.         }
  619.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("6")) {
  620.             day_spinner_array = getResources().getStringArray(R.array.days_30_arrays);
  621.         }
  622.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("7")) {
  623.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  624.         }
  625.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("8")) {
  626.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  627.         }
  628.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("9")) {
  629.             day_spinner_array = getResources().getStringArray(R.array.days_30_arrays);
  630.         }
  631.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("10")) {
  632.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  633.         }
  634.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("11")) {
  635.             day_spinner_array = getResources().getStringArray(R.array.days_30_arrays);
  636.         }
  637.         if (monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()).equals("12")) {
  638.             day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  639.         }
  640.  
  641.         Log.d("month_position", monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()));
  642. //        day_spinner_array = getResources().getStringArray(R.array.days_31_arrays);
  643.         ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
  644.                 R.layout.period_spinner_item, day_spinner_array);
  645. //
  646. //        //selected item will look like a spinner set from XML
  647.         spinnerArrayAdapter.setDropDownViewResource(R.layout.period_spinner_dropdown_item);
  648.         day_spinner.setAdapter(spinnerArrayAdapter);
  649.         day_spinner.setSelection(((ArrayAdapter) day_spinner.getAdapter()).getPosition(today));
  650.  
  651.         day_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  652.             @Override
  653.             public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
  654.                 if (b) {
  655.                     dayCheck = dayCheck + 1;
  656.                     if (dayCheck > 1) {
  657.                         date = year_spinner.getSelectedItem() + "/"
  658.                                 + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()) + "/"
  659.                                 + (String) adapterView.getItemAtPosition(i);
  660.                         getDataFrom(date, "hours");
  661. //                        Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
  662.                     }
  663.                 }
  664.             }
  665.  
  666.             @Override
  667.             public void onNothingSelected(AdapterView<?> adapterView) {
  668.  
  669.             }
  670.         });
  671.     }
  672.  
  673.     private void getDataFrom(String period, final String label) {
  674.         Log.d("report_api_", "api_request made");
  675.         client.cancelAllRequests(true);
  676.         client.cancelRequests(getApplicationContext(), true);
  677.         ConnectivityManager cm =
  678.                 (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  679.  
  680.         NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
  681.         boolean isConnected = activeNetwork != null &&
  682.                 activeNetwork.isConnectedOrConnecting();
  683.         if (isConnected) {
  684.             String url = getResources().getString(R.string.url) + "sales/" + period
  685.                     + "/api";
  686.             RequestParams params = new RequestParams();
  687.             client.addHeader("class", "Business");
  688.             client.addHeader("attendant_name", asp.getAttendantName());
  689.             client.addHeader("attendant_id", asp.getAttendantId());
  690.             client.addHeader(getResources().getString(R.string.api_token), asp.getApiKey());
  691.             client.get(url,
  692.                     params, new AsyncHttpResponseHandler() {
  693.                         @Override
  694.                         public void onStart() {
  695.  
  696.                             Log.d("report_api_", "api_request started");
  697.                             progressBar.setVisibility(View.VISIBLE);
  698.                         }
  699.  
  700.                         @Override
  701.                         public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
  702.                             String s = new String(responseBody);
  703.                             Log.d("sale_reports_", s);
  704.                             try {
  705.                                 Log.d("report_api_", "api_request successful");
  706.                                 JSONObject objs = new JSONObject(s);
  707.                                 HashMap<String, String> map = new HashMap<String, String>();
  708.                                 Boolean success = objs.getBoolean("success");
  709.                                 if (success) {
  710.  
  711.                                     JSONArray array = objs.getJSONArray("data");
  712.                                     sh.setLabelType(label);
  713.                                     new AsyncUpdateSalesToDisplayGraph(array, label).execute();
  714.  
  715.                                 } else {
  716.                                     String failure = objs.getString("message");
  717.                                     Crouton.makeText(
  718.                                             Reports.this,
  719.                                             failure,
  720.                                             Style.ALERT, com.duka.R.id.report_holder).show();
  721.  
  722.                                 }
  723.  
  724.                             } catch (JSONException e) {
  725.  
  726.                             }
  727.                         }
  728.  
  729.                         @Override
  730.                         public void onFailure(int statusCode, Header[] headers,
  731.                                               byte[] responseBody, Throwable error) {
  732.                             progressBar.setVisibility(View.INVISIBLE);
  733.                             Log.d("something_went_wrong", String.valueOf(error));
  734.                             //errorDialog();
  735.                             Crouton.makeText(Reports.this, "Check your network connection",
  736.                                     Style.ALERT, com.duka.R.id.report_holder).show();
  737.  
  738.                         }
  739.                     }
  740.  
  741.             );
  742.         } else {
  743.             Crouton.makeText(Reports.this, "Check your network connection",
  744.                     Style.ALERT, com.duka.R.id.report_holder).show();
  745.         }
  746.     }
  747.  
  748.     public void onRadioButtonClicked(View view) {
  749.         // Is the button now checked?
  750.         boolean checked = ((RadioButton) view).isChecked();
  751.         // Check which radio button was clicked
  752.         switch (view.getId()) {
  753.             case R.id.hour_radioBtn:
  754.                 if (checked) {
  755.                     dayButton.setChecked(false);
  756.                     monthButton.setChecked(false);
  757.                     layout1.setVisibility(View.VISIBLE);
  758.                     layout2.setVisibility(View.VISIBLE);
  759.                     layout3.setVisibility(View.VISIBLE);
  760.                     isDay = true;
  761.                     isMonth = true;
  762.                     isYear = true;
  763.                     date = year_spinner.getSelectedItem() + "/"
  764.                             + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem()) + "/"
  765.                             + day_spinner.getSelectedItem();
  766.                     getDataFrom(date, "hours");
  767.                 }
  768.                 break;
  769.             case R.id.day_radioBtn:
  770.                 if (checked) {
  771.                     hourButton.setChecked(false);
  772.                     monthButton.setChecked(false);
  773.                     layout3.setVisibility(View.VISIBLE);
  774.                     layout1.setVisibility(View.VISIBLE);
  775.                     layout2.setVisibility(View.GONE);
  776.                     isDay = false;
  777.                     isMonth = true;
  778.                     isYear = true;
  779.                     date = year_spinner.getSelectedItem() + "/"
  780.                             + monthPosition.getMonthPostion("" + month_spinner.getSelectedItem());
  781.                     getDataFrom(date, "days");
  782.  
  783.                 }
  784.                 break;
  785.             case R.id.month_radioBtn:
  786.                 if (checked) {
  787.                     dayButton.setChecked(false);
  788.                     hourButton.setChecked(false);
  789.                     layout1.setVisibility(View.VISIBLE);
  790.                     layout2.setVisibility(View.GONE);
  791.                     layout3.setVisibility(View.GONE);
  792.                     isDay = false;
  793.                     isMonth = false;
  794.                     isYear = true;
  795.                     date = year_spinner.getSelectedItem() + "";
  796.                     getDataFrom(date, "months");
  797.                 }
  798.                 break;
  799.         }
  800.     }
  801.  
  802.     @Override
  803.     public boolean onOptionsItemSelected(MenuItem item) {
  804.         // Handle action bar item clicks here. The action bar will
  805.         // automatically handle clicks on the Home/Up button, so long
  806.         // as you specify a parent activity in AndroidManifest.xml.
  807.         int id = item.getItemId();
  808.  
  809.         //noinspection SimplifiableIfStatement
  810.  
  811.         if (id == android.R.id.home) {
  812.             finish();
  813. //            MainActivity ma = new MainActivity();
  814. //            ma.openResideMenu();
  815.             return true;
  816.         }
  817.         return super.onOptionsItemSelected(item);
  818.     }
  819.  
  820.     private String getDayFormatted(String dateStr) {
  821.         DateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  822.         DateFormat writeFormat = new SimpleDateFormat("dd");
  823.         Date date = null;
  824.         try {
  825.             date = readFormat.parse(dateStr);
  826.         } catch (ParseException e) {
  827.             e.printStackTrace();
  828.         }
  829.         String formattedDate = writeFormat.format(date);
  830.         return formattedDate;
  831.     }
  832.  
  833.     private String getTimeFormattedInAMPM(String dateStr) {
  834.         DateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  835.         DateFormat writeFormat = new SimpleDateFormat("ha");
  836.         Date date = null;
  837.         try {
  838.             date = readFormat.parse(dateStr);
  839.         } catch (ParseException e) {
  840.             e.printStackTrace();
  841.         }
  842.         String formattedDate = writeFormat.format(date);
  843.         return formattedDate;
  844.     }
  845.  
  846.     private String getMonthFormatted(String dateStr) {
  847.         DateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  848.         DateFormat writeFormat = new SimpleDateFormat("MMM ");
  849.         Date date = null;
  850.         try {
  851.             date = readFormat.parse(dateStr);
  852.         } catch (ParseException e) {
  853.             e.printStackTrace();
  854.         }
  855.         String formattedDate = writeFormat.format(date);
  856.         return formattedDate;
  857.     }
  858.  
  859.     public static class SortBasedOnCreatedAt implements Comparator<JSONObject> {
  860.         String CompareString1 = "", CompareString2 = "";
  861.  
  862.         /*
  863.         * (non-Javadoc)
  864.         *
  865.         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
  866.         * lhs- 1st message in the form of json object. rhs- 2nd message in the form
  867.         * of json object.
  868.         */
  869.         @Override
  870.         public int compare(JSONObject lhs, JSONObject rhs) {
  871.             try {
  872. //                return Integer.valueOf(lhs.getString("created_at")) > Integer.valueOf(rhs.getString("created_at"))
  873. //                        ? 1 : (Integer.valueOf(lhs.getString("created_at")) < Integer.valueOf(rhs.getString("created_at")) ? -1 : 0);
  874.  
  875.                 CompareString1 = lhs.getString("created_at"); //Key must be present in JSON
  876.                 CompareString2 = rhs.getString("created_at"); //Key must be present in JSON
  877.  
  878.             } catch (JSONException e) {
  879.                 e.printStackTrace();
  880.             }
  881.             return CompareString1.compareTo(CompareString2);
  882.  
  883.         }
  884.     }
  885.  
  886.     class AsyncUpdateSalesToDisplayGraph extends AsyncTask<Void, String, Void> {
  887.         Activity activity;
  888.         JSONArray sales;
  889.         JSONObject sale_obj;
  890.         ArrayList<Entry> sales_values_1 = new ArrayList<>();
  891.         ArrayList<String> sales_labels_1 = new ArrayList<>();
  892.         ArrayList<Entry> product_values_1 = new ArrayList<>();
  893.         ArrayList<String> product_labels_1 = new ArrayList<>();
  894.         ArrayList<Entry> customer_values_1 = new ArrayList<>();
  895.         ArrayList<String> customer_labels_1 = new ArrayList<>();
  896.         ArrayList<Entry> staff_values_1 = new ArrayList<>();
  897.         ArrayList<String> staff_labels_1 = new ArrayList<>();
  898.         ArrayList<Entry> sales_values;
  899.         ArrayList<String> sales_labels;
  900.  
  901.         ArrayList<Entry> product_values;
  902.         ArrayList<String> product_labels;
  903.         ArrayList<Entry> customer_values;
  904.         ArrayList<String> customer_labels;
  905.         ArrayList<Entry> staff_values;
  906.         ArrayList<String> staff_labels;
  907.  
  908.         ArrayList<String> sales_count;
  909.  
  910.         String label;
  911.  
  912.         public AsyncUpdateSalesToDisplayGraph(JSONArray sale, String label) throws JSONException {
  913.             this.sales = getSortedListByDate(sale);
  914.             this.label = label;
  915.         }
  916.  
  917.         @Override
  918.         protected Void doInBackground(Void... params) {
  919.             Log.d("array_report_track", "adding sales in background");
  920.             JSONObject groupedSales = new JSONObject();
  921.             JSONObject groupedProducts = new JSONObject();
  922.             JSONObject groupedCustomers = new JSONObject();
  923.             JSONObject groupedStaff = new JSONObject();
  924.  
  925.             for (int i = 0; i < sales.length(); i++) {
  926. //                for (int i = 0; i < getSortedListByDate(sales).length(); i++) {
  927.  
  928.                 try {
  929.                     sale_obj = (JSONObject) sales.get(i);
  930. //                        sale_obj = (JSONObject) getSortedListByDate(sales).get(i);
  931.                     //sales
  932.                     if (label.equals("hours")) {
  933.  
  934.                         String amPM = getTimeFormattedInAMPM(sale_obj.getString("created_at"));
  935.                         int count = 1;
  936.                         if (groupedSales.has(amPM)) {
  937.                             int current_count = groupedSales.getInt(amPM); // read the current count
  938.                             count = Integer.valueOf(current_count) + 1; // increment by 1
  939.                         }
  940.                         groupedSales.put(amPM, count);
  941.                         sales_values_1.add(new Entry(Float.valueOf(String.valueOf(count)), i));
  942.                         sales_labels_1.add(amPM);
  943.                     }
  944.                     if (label.equals("days")) {
  945.                         String days = getDayFormatted(sale_obj.getString("created_at"));
  946.                         int count = 1;
  947.                         if (groupedSales.has(days)) {
  948.                             int current_count = groupedSales.getInt(days); // read the current count
  949.                             count = Integer.valueOf(current_count) + 1; // increment by 1
  950.                         }
  951.                         groupedSales.put(days, count);
  952.                         sales_values_1.add(new Entry(Float.valueOf(String.valueOf(count)), i));
  953.                         sales_labels_1.add(days);
  954.                     }
  955.                     if (label.equals("months")) {
  956.                         String months = getMonthFormatted(sale_obj.getString("created_at"));
  957. //                        String months = "Jan";
  958.                         int count = 1;
  959.                         if (groupedSales.has(months)) {
  960.                             int current_count = groupedSales.getInt(months); // read the current count
  961.                             count = Integer.valueOf(current_count) + 1; // increment by 1
  962.                         }
  963.                         groupedSales.put(months, count);
  964.                         sales_values_1.add(new Entry(Float.valueOf(String.valueOf(count)), i));
  965.                         sales_labels_1.add(months);
  966.                     }
  967.  
  968.                     //products
  969.                     String productName = sale_obj.getString("name");
  970.                     int quantity = Integer.parseInt(sale_obj.getString("quantity"));
  971.                     if (groupedProducts.has(productName)) {
  972.                         int current_quantity = groupedProducts.getInt(productName);
  973.                         // read the current count
  974.                         // increment by quantity
  975.                         quantity = current_quantity + Integer.parseInt(sale_obj.getString("quantity"));
  976.                     }
  977.                     groupedProducts.put(productName, quantity);
  978.                     product_values_1.add(new Entry(Float.valueOf(String.valueOf(quantity)), i));
  979.                     product_labels_1.add(quantity + " " + productName);
  980.                     Log.d("array_report_products", groupedProducts.toString());
  981.  
  982.                     //customer
  983.                     String customerName = sale_obj.getString("customer_first_name") + " "
  984.                             + sale_obj.getString("customer_first_name");
  985.                     int customerQuantity = Integer.parseInt(sale_obj.getString("quantity"));
  986.                     if (groupedCustomers.has(customerName)) {
  987.                         int current_quantity = groupedCustomers.getInt(customerName); // read the current count
  988.                         // increment by the quantity
  989.                         customerQuantity = current_quantity + Integer.parseInt(sale_obj.getString("quantity"));
  990.                     }
  991.                     groupedCustomers.put(customerName, customerQuantity);
  992.                     customer_values_1.add(new Entry(Float.valueOf(String.valueOf(customerQuantity)), i));
  993.                     customer_labels_1.add(customerName + " " + customerQuantity);
  994.  
  995.                     Log.d("array_report_customer", groupedCustomers.toString());
  996.  
  997.                     //staff
  998.                     String staffName = sale_obj.getString("attendant_name");
  999.                     double price = Double.parseDouble(sale_obj.getString("price"));
  1000.                     if (groupedStaff.has(staffName)) {
  1001.                         double current_price = groupedStaff.getDouble(staffName); // read the current count
  1002.                         // increment by the price
  1003.                         price = current_price + Double.parseDouble(sale_obj.getString("price"));
  1004.                     }
  1005.                     groupedStaff.put(staffName, price);
  1006.                     staff_values_1.add(new Entry(Float.valueOf(String.valueOf(price)), i));
  1007.                     staff_labels_1.add(staffName + " " + price);
  1008.                     Log.d("array_report_staff", groupedStaff.toString());
  1009.                 } catch (JSONException e) {
  1010.                     e.printStackTrace();
  1011.                 }
  1012.  
  1013.             }
  1014.  
  1015.             Log.d("array_report_track", "done adding sales in background");
  1016.  
  1017. /*
  1018.             Type type = new TypeToken<Map<String, String>>() {
  1019.             }.getType();
  1020.             //sales loop
  1021.             Map<String, String> sales_map = new Gson().fromJson(String.valueOf(groupedSales), type);
  1022.             Log.d("gson_vals", sales_map.toString());
  1023.             int i = 0;
  1024.             for (Map.Entry<String, String> entry : sales_map.entrySet()) {
  1025.                 String key = entry.getKey();
  1026.                 sales_values_1.add(new Entry(Float.valueOf(String.valueOf(entry.getValue())), i));
  1027.                 sales_labels_1.add(key);
  1028.                 i++;
  1029.             }
  1030.  
  1031.             Log.d("array_report_track", "done adding sales to x and y");
  1032.             //products iterator
  1033.             Map<String, String> products_map = new Gson().fromJson(String.valueOf(groupedProducts), type);
  1034.             Log.d("gson_vals_products", products_map.toString());
  1035.             int i2 = 0;
  1036.             for (Map.Entry<String, String> entry : products_map.entrySet()) {
  1037.                 String key = entry.getKey();
  1038.                 product_values_1.add(new Entry(Float.valueOf(String.valueOf(entry.getValue())), i2));
  1039.                 product_labels_1.add(entry.getValue() + " " + key);
  1040.                 i2++;
  1041.             }
  1042.  
  1043.             Log.d("array_report_track", "done adding products to x and y");
  1044.             //customers iterator
  1045.             Map<String, String> customers_map = new Gson().fromJson(String.valueOf(groupedCustomers), type);
  1046.             Log.d("gson_vals_customers", customers_map.toString());
  1047.             int i3 = 0;
  1048.             for (Map.Entry<String, String> entry : customers_map.entrySet()) {
  1049.                 String key = entry.getKey();
  1050.                 customer_values_1.add(new Entry(Float.valueOf(String.valueOf(entry.getValue())), i3));
  1051.                 customer_labels_1.add(entry.getValue() + " " + key);
  1052.                 i3++;
  1053.             }
  1054.  
  1055.             Log.d("array_report_track", "done adding customers to x and y");
  1056.             //staff iterator
  1057.             DecimalFormat mFormat = new DecimalFormat("###,###,###");
  1058.             Map<String, String> staff_map = new Gson().fromJson(String.valueOf(groupedStaff), type);
  1059.             Log.d("gson_vals_staff", staff_map.toString());
  1060.             int i4 = 0;
  1061.             for (Map.Entry<String, String> entry : staff_map.entrySet()) {
  1062.                 String key = entry.getKey();
  1063.                 staff_values_1.add(new Entry(Float.valueOf(String.valueOf(entry.getValue())), i4));
  1064.                 staff_labels_1.add(entry.getValue() + " " + key);
  1065.                 i4++;
  1066.             }*/
  1067.  
  1068.  
  1069.          /*   sales_values = sh.dateValues();
  1070.             sales_labels = sh.hour_labels();
  1071.             product_values = sh.date_products_values();
  1072.             product_labels = sh.product_labels();
  1073.             customer_values = sh.date_customer_values();
  1074.             customer_labels = sh.customer_labels();
  1075.             staff_values = sh.date_staff_values();
  1076.             staff_labels = sh.staff_labels();*/
  1077.  
  1078.             return null;
  1079.         }
  1080.  
  1081.         @Override
  1082.         protected void onPostExecute(Void unused) {
  1083.  
  1084.             progressBar.setVisibility(View.INVISIBLE);
  1085.             Log.d("sum_sales_values_1", sales_values_1.toString() + "/" + sales_labels_1.toString());
  1086.             if (label.equals("hours")) {
  1087.                 salesXTitle.setText("TIME");
  1088.             }
  1089.             if (label.equals("days")) {
  1090.                 salesXTitle.setText("DATES");
  1091.             }
  1092.             if (label.equals("months")) {
  1093.                 salesXTitle.setText("MONTHS");
  1094.             }
  1095.             initializeSalesMPChart(sales_values_1, sales_labels_1, label);
  1096.             initializeProductPieChart(product_values_1, product_labels_1);
  1097.             initializeCustomerPieChart(customer_values_1, customer_labels_1);
  1098.             initializeStaffPieChart(staff_values_1, staff_labels_1);
  1099.  
  1100.         }
  1101.     }
  1102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement