Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Declaramos todos los elementos */
- private String namePay,id_cxPay,debePay;
- private int vortPay = 0;
- EditText campoNombrePago,campoAddPago, campoAddDetailPago;
- TextView txtNombreApellidoPago, txtDeudaPago, txtIdPago;
- Button btnAgregarPago;
- ProgressBar progressBarPago;
- //Declaramos los objetos JSON
- RequestQueue requestPagoConsulta,requestCreditPago;
- JsonObjectRequest jsonObjectRequestConsulta, jsonObjectRequestPago;
- //METODO ON CREATE VIEW SOBREESCRITO
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View vista = inflater.inflate(R.layout.fragment_recibir_pago, container, false);
- campoNombrePago = (EditText) vista.findViewById(R.id.campoNombrePago);
- txtNombreApellidoPago = (TextView) vista.findViewById(R.id.txtNombreApellidoPago);
- txtDeudaPago = (TextView) vista.findViewById(R.id.txtDeudaPago);
- txtIdPago = (TextView) vista.findViewById(R.id.txtIdPago);
- progressBarPago = (ProgressBar) vista.findViewById(R.id.progressBarPago);
- progressBarPago.setVisibility(vista.INVISIBLE);
- campoAddPago = (EditText) vista.findViewById(R.id.campoAddPago);
- campoAddDetailPago = (EditText) vista.findViewById(R.id.campoAddDetailPago);
- btnAgregarPago = (Button) vista.findViewById(R.id.btnAddPago);
- requestPagoConsulta = Volley.newRequestQueue(getContext()); //consulta cliente
- requestCreditPago = Volley.newRequestQueue(getContext()); //web service agregar pago
- //================= Campo Nombre =====================
- campoNombrePago.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
- if (i == EditorInfo.IME_ACTION_SEARCH){
- cargarConsulta();
- progressBarPago.setVisibility(progressBarPago.VISIBLE);
- minimizarTeclado();
- return true;
- }
- return false;
- }
- });
- //===================== campo ADDCREDITO =====================
- btnAgregarPago.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (namePay.toString().isEmpty()){
- Toast.makeText(getContext(),"No has buscado al cliente.",Toast.LENGTH_SHORT).show();
- }else {
- cargarPago();
- }
- }
- });
- return vista;
- }
- private void cargarPago() {
- progressBarPago.setVisibility(progressBarPago.VISIBLE);
- if (campoAddPago.getText().toString().isEmpty() && campoAddDetailPago.getText().toString().isEmpty()) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle("ERROR")
- .setMessage("Es necesario llenar todos los campos.")
- .setPositiveButton("OK", null);
- builder.show();
- progressBarPago.setVisibility(progressBarPago.INVISIBLE);
- } else {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle("CONFIRMACIÓN DE PAGO")
- .setMessage(Html.fromHtml("El cliente <b>" + namePay + "</b> debe <font color='#f50616'>$" +debePay
- + "</font><br> se le esta cobrando<b> $" + campoAddPago.getText().toString() + "</b><br><br> ¿Es correcto?"))
- .setPositiveButton("SI", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- String url = "http://servidorremoto/add_pay_credit.php?id_cliente=" + id_cxPay + "&nom_cliente=" +
- namePay + "&detalle=" + campoAddDetailPago.getText().toString() + "&monto=-" + campoAddPago.getText().toString();
- url = url.replace(" ", "%20"); //para reemplazar espacios con porcentajes
- jsonObjectRequestPago = new JsonObjectRequest(Request.Method.GET, url, null,
- RecibirPagoFragment.this, RecibirPagoFragment.this);
- requestCreditPago.add(jsonObjectRequestPago);
- }
- })
- .setNegativeButton("NO", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- Toast.makeText(getContext(), "VERIFICA MONTO Y CLIENTE", Toast.LENGTH_LONG).show();
- progressBarPago.setVisibility(View.INVISIBLE);
- }
- });
- builder.show();
- }
- }
- private void minimizarTeclado() {
- InputMethodManager imm =
- (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(campoNombrePago.getWindowToken(), 0);
- }
- private void cargarConsulta() {
- //Toast.makeText(getContext(),"Estamos buscando.",Toast.LENGTH_LONG).show();
- String url = "http://servidorremoto/konsult_user.php?cliente="+campoNombrePago.getText().toString();
- url = url.replace(" ","%20"); //para reemplazar espacios con porcentajes
- vortPay = 1;
- jsonObjectRequestConsulta = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
- requestPagoConsulta.add(jsonObjectRequestConsulta);
- }
- @Override
- public void onErrorResponse(VolleyError error) {
- progressBarPago.setVisibility(progressBarPago.INVISIBLE);
- Toast.makeText(getContext(),"Error"+error.getMessage().toString(),Toast.LENGTH_SHORT);
- }
- @Override
- public void onResponse(JSONObject response) {
- progressBarPago.setVisibility(progressBarPago.INVISIBLE);
- if (vortPay==1){
- Cliente tmpClientePago = new Cliente();
- JSONArray jsonPago = response.optJSONArray("cliente");
- JSONObject jsonObjectPago = null;
- try {
- jsonObjectPago=jsonPago.getJSONObject(0);
- tmpClientePago.setCliente(jsonObjectPago.optString("cliente"));
- tmpClientePago.setId_cliente(jsonObjectPago.optInt("id_cliente"));
- tmpClientePago.setDeuda_total(jsonObjectPago.optDouble("deuda_total"));
- }catch (JSONException e){
- e.printStackTrace();
- Toast.makeText(getContext(),"ENTRO EN EL TRYCATH "+e.getMessage().toString(),Toast.LENGTH_LONG);
- }
- txtIdPago.setText("ID: "+tmpClientePago.getId_cliente().toString());
- txtNombreApellidoPago.setText(""+tmpClientePago.getCliente().toString());
- txtDeudaPago.setText("$"+tmpClientePago.getDeuda_total().toString());
- if (tmpClientePago.getCliente().toString().equals("no registrado")){
- Toast.makeText(getContext(),"USUARIO NO ENCONTRADO, VERIFICA LA BUSQUEDA",Toast.LENGTH_LONG);
- }else {
- Toast.makeText(getContext(),"EXITO: "+tmpClientePago.getCliente().toString(),Toast.LENGTH_LONG).show();
- id_cxPay = tmpClientePago.getId_cliente().toString();
- namePay = tmpClientePago.getCliente().toString();
- vortPay = 0;
- debePay = tmpClientePago.getDeuda_total().toString();
- btnAgregarPago.setVisibility(View.VISIBLE);
- }
- }else {
- campoAddPago.setText("");
- campoAddDetailPago.setText("");
- cargarConsulta();
- }
- }
Add Comment
Please, Sign In to add comment