private void setCheckOut2DB(boolean sent) { CheckIn.updateActive(getActivity(), currentCheckin.get("id_checkin"), "noactive"); String id_checkout = String.valueOf(System.currentTimeMillis()); String date_time = DatesHelper.getStringDate(new Date()); if (!sent) { // id_checkout = "N" + id_checkout; CheckOut.updateInsert( getActivity(), currentCheckin.get("id_checkin"), id_checkout, "no_sent", visit_id, date_time); } else { CheckOut.updateInsert( getActivity(), currentCheckin.get("id_checkin"), id_checkout, "sent", visit_id, date_time); } }
private void setCheckIn2DB(boolean sent, String id_visit_session) { String id_checkin = String.valueOf(System.currentTimeMillis()); String date_time = DatesHelper.getStringDate(new Date()); if (!sent) { // id_checkin = "N" + id_checkin; CheckIn.insert( getActivity(), id_checkin, "no_sent", latitude, longitude, visit_id, date_time, id_visit_session, "active"); } else { CheckIn.insert( getActivity(), id_checkin, "sent", latitude, longitude, visit_id, date_time, id_visit_session, "active"); } CheckOut.insert( getActivity(), id_checkin, "pre_checkout" + id_checkin, "no_sent", visit_id, date_time, id_visit_session); checkin = "active"; }
@Override public void clickFromList(int position) { Log.d(LOG_VISIT_FRAGMENT, "Position: " + position); Map<String, String> params = new HashMap<String, String>(); currentCheckin = CheckIn.getActiveMap(getActivity(), visit_id); if (currentCheckin.size() > 0) checkin = "active"; else checkin = "noactive"; Log.e("CHECKIN CLICK", checkin); if (position == 0) { // if(checkin.equalsIgnoreCase("no_checkin")) { if (!checkin.equalsIgnoreCase("active")) { params.put("latitude", String.valueOf(latitude)); params.put("longitude", String.valueOf(longitude)); params.put("visit_id", visit_id); params.put("date_time", "" + DatesHelper.getStringDateDays(new Date())); prepareRequest(METHOD.SEND_START_VISIT, params, true, true); } else if (checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "La visita ya fue iniciada", Toast.LENGTH_SHORT).show(); } } else if (position == 1) { if (checkin.equalsIgnoreCase("active")) { // prepareRequest(METHOD.GET_PRODUCT,params,true); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentOrder fragment = new FragmentOrder(); fragment.tag = FRAGMENT_TAG.FRAG_ORDERS.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); // fragmentTransaction.replace(R.id.container, fragment, // TrackerFragment.FRAGMENT_TAG.FRAG_HOME.toString()); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_ORDERS.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 2) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentPromotions fragment = new FragmentPromotions(); fragment.tag = FRAGMENT_TAG.FRAG_SALES.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_SALES.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (position == 3) { if (checkin.equalsIgnoreCase("active")) { FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentCashing fragment = new FragmentCashing(); fragment.tag = FRAGMENT_TAG.FRAG_PAYMENT.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.container, fragment, FRAGMENT_TAG.FRAG_PAYMENT.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 4) { if (checkin.equalsIgnoreCase("active")) { // if (WorkPlan.getAnswersandDatetimeByVisit(context, visit_id).get("answers").equals("")) { if (FormAnswers.getAnswers(context, visit_id).equals("")) { try { id_Form = Form.getAllInMaps(context) .get(0) .get("id_form"); // Si no hay formulario se puede causar una excepcion // por el ".get("id_form")" bundle.putString("id_form", id_Form); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentForms fragment = new FragmentForms(); fragment.tag = FRAGMENT_TAG.FRAG_FORMS.toString(); fragment.section_index = NavigationDrawerFragment.WORK_PLAN; fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace( R.id.container, fragment, FRAGMENT_TAG.FRAG_FORMS.toString()); fragmentTransaction.commit(); ((MainActivity) getActivity()).depthCounter = 3; } catch (Exception e) { // No hay formularios para esta visita Toast.makeText(getActivity(), "No hay formulario para este cliente", Toast.LENGTH_LONG) .show(); } } else { Toast.makeText( getActivity(), "Ya se envio un formulario para esta visita", Toast.LENGTH_LONG) .show(); } } else if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } } else if (position == 5) { if (!checkin.equalsIgnoreCase("active")) { Toast.makeText(getActivity(), "Primero haz Check In", Toast.LENGTH_SHORT).show(); } else { String id_visit_session = CheckIn.getIdVisitSession(getActivity(), currentCheckin.get("id_checkin")); checkoutFlag = true; if (!id_visit_session.equalsIgnoreCase("no_id_visit_session")) { params.put("visit_id", visit_id); params.put("date_time", "" + DatesHelper.getStringDateDays(new Date())); params.put("id_visit_session", "" + id_visit_session); prepareRequest(METHOD.END_VISIT, params, true, true); } else if (id_visit_session.equalsIgnoreCase("no_id_visit_session")) { RequestManager.sharedInstance() .showConfirmationDialogWithListener( "No fue posible enviar el Check Out, se registrara en modo OFFLINE", getActivity(), this); setCheckOut2DB(false); getActivity().onBackPressed(); } } } }