Advertisement
stevekamau

Reports

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