Guest User

Untitled

a guest
Jan 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. /* Declaramos todos los elementos */
  2.  
  3. private String namePay,id_cxPay,debePay;
  4. private int vortPay = 0;
  5. EditText campoNombrePago,campoAddPago, campoAddDetailPago;
  6. TextView txtNombreApellidoPago, txtDeudaPago, txtIdPago;
  7. Button btnAgregarPago;
  8.  
  9. ProgressBar progressBarPago;
  10.  
  11. //Declaramos los objetos JSON
  12. RequestQueue requestPagoConsulta,requestCreditPago;
  13. JsonObjectRequest jsonObjectRequestConsulta, jsonObjectRequestPago;
  14.  
  15. //METODO ON CREATE VIEW SOBREESCRITO
  16.  
  17. @Override
  18. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  19. Bundle savedInstanceState) {
  20. // Inflate the layout for this fragment
  21.  
  22. View vista = inflater.inflate(R.layout.fragment_recibir_pago, container, false);
  23.  
  24. campoNombrePago = (EditText) vista.findViewById(R.id.campoNombrePago);
  25. txtNombreApellidoPago = (TextView) vista.findViewById(R.id.txtNombreApellidoPago);
  26. txtDeudaPago = (TextView) vista.findViewById(R.id.txtDeudaPago);
  27. txtIdPago = (TextView) vista.findViewById(R.id.txtIdPago);
  28.  
  29. progressBarPago = (ProgressBar) vista.findViewById(R.id.progressBarPago);
  30. progressBarPago.setVisibility(vista.INVISIBLE);
  31.  
  32. campoAddPago = (EditText) vista.findViewById(R.id.campoAddPago);
  33. campoAddDetailPago = (EditText) vista.findViewById(R.id.campoAddDetailPago);
  34. btnAgregarPago = (Button) vista.findViewById(R.id.btnAddPago);
  35.  
  36. requestPagoConsulta = Volley.newRequestQueue(getContext()); //consulta cliente
  37. requestCreditPago = Volley.newRequestQueue(getContext()); //web service agregar pago
  38.  
  39.  
  40. //================= Campo Nombre =====================
  41. campoNombrePago.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  42. @Override
  43. public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
  44. if (i == EditorInfo.IME_ACTION_SEARCH){
  45. cargarConsulta();
  46.  
  47. progressBarPago.setVisibility(progressBarPago.VISIBLE);
  48. minimizarTeclado();
  49. return true;
  50. }
  51. return false;
  52. }
  53. });
  54.  
  55. //===================== campo ADDCREDITO =====================
  56.  
  57. btnAgregarPago.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View view) {
  60. if (namePay.toString().isEmpty()){
  61. Toast.makeText(getContext(),"No has buscado al cliente.",Toast.LENGTH_SHORT).show();
  62. }else {
  63. cargarPago();
  64. }
  65. }
  66. });
  67. return vista;
  68. }
  69.  
  70. private void cargarPago() {
  71. progressBarPago.setVisibility(progressBarPago.VISIBLE);
  72.  
  73. if (campoAddPago.getText().toString().isEmpty() && campoAddDetailPago.getText().toString().isEmpty()) {
  74.  
  75. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
  76. .setTitle("ERROR")
  77. .setMessage("Es necesario llenar todos los campos.")
  78. .setPositiveButton("OK", null);
  79. builder.show();
  80. progressBarPago.setVisibility(progressBarPago.INVISIBLE);
  81. } else {
  82. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
  83. .setTitle("CONFIRMACIÓN DE PAGO")
  84. .setMessage(Html.fromHtml("El cliente <b>" + namePay + "</b> debe <font color='#f50616'>$" +debePay
  85. + "</font><br> se le esta cobrando<b> $" + campoAddPago.getText().toString() + "</b><br><br> ¿Es correcto?"))
  86. .setPositiveButton("SI", new DialogInterface.OnClickListener() {
  87. @Override
  88. public void onClick(DialogInterface dialogInterface, int i) {
  89. String url = "http://servidorremoto/add_pay_credit.php?id_cliente=" + id_cxPay + "&nom_cliente=" +
  90. namePay + "&detalle=" + campoAddDetailPago.getText().toString() + "&monto=-" + campoAddPago.getText().toString();
  91.  
  92. url = url.replace(" ", "%20"); //para reemplazar espacios con porcentajes
  93.  
  94. jsonObjectRequestPago = new JsonObjectRequest(Request.Method.GET, url, null,
  95. RecibirPagoFragment.this, RecibirPagoFragment.this);
  96.  
  97. requestCreditPago.add(jsonObjectRequestPago);
  98. }
  99. })
  100. .setNegativeButton("NO", new DialogInterface.OnClickListener() {
  101. @Override
  102. public void onClick(DialogInterface dialogInterface, int i) {
  103. Toast.makeText(getContext(), "VERIFICA MONTO Y CLIENTE", Toast.LENGTH_LONG).show();
  104. progressBarPago.setVisibility(View.INVISIBLE);
  105. }
  106. });
  107. builder.show();
  108. }
  109. }
  110.  
  111. private void minimizarTeclado() {
  112. InputMethodManager imm =
  113. (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  114. imm.hideSoftInputFromWindow(campoNombrePago.getWindowToken(), 0);
  115. }
  116.  
  117. private void cargarConsulta() {
  118. //Toast.makeText(getContext(),"Estamos buscando.",Toast.LENGTH_LONG).show();
  119. String url = "http://servidorremoto/konsult_user.php?cliente="+campoNombrePago.getText().toString();
  120.  
  121. url = url.replace(" ","%20"); //para reemplazar espacios con porcentajes
  122. vortPay = 1;
  123.  
  124. jsonObjectRequestConsulta = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
  125. requestPagoConsulta.add(jsonObjectRequestConsulta);
  126. }
  127.  
  128. @Override
  129. public void onErrorResponse(VolleyError error) {
  130. progressBarPago.setVisibility(progressBarPago.INVISIBLE);
  131. Toast.makeText(getContext(),"Error"+error.getMessage().toString(),Toast.LENGTH_SHORT);
  132. }
  133.  
  134. @Override
  135. public void onResponse(JSONObject response) {
  136. progressBarPago.setVisibility(progressBarPago.INVISIBLE);
  137. if (vortPay==1){
  138.  
  139. Cliente tmpClientePago = new Cliente();
  140.  
  141. JSONArray jsonPago = response.optJSONArray("cliente");
  142. JSONObject jsonObjectPago = null;
  143.  
  144. try {
  145. jsonObjectPago=jsonPago.getJSONObject(0);
  146. tmpClientePago.setCliente(jsonObjectPago.optString("cliente"));
  147. tmpClientePago.setId_cliente(jsonObjectPago.optInt("id_cliente"));
  148. tmpClientePago.setDeuda_total(jsonObjectPago.optDouble("deuda_total"));
  149.  
  150. }catch (JSONException e){
  151. e.printStackTrace();
  152. Toast.makeText(getContext(),"ENTRO EN EL TRYCATH "+e.getMessage().toString(),Toast.LENGTH_LONG);
  153. }
  154. txtIdPago.setText("ID: "+tmpClientePago.getId_cliente().toString());
  155. txtNombreApellidoPago.setText(""+tmpClientePago.getCliente().toString());
  156. txtDeudaPago.setText("$"+tmpClientePago.getDeuda_total().toString());
  157.  
  158. if (tmpClientePago.getCliente().toString().equals("no registrado")){
  159. Toast.makeText(getContext(),"USUARIO NO ENCONTRADO, VERIFICA LA BUSQUEDA",Toast.LENGTH_LONG);
  160. }else {
  161. Toast.makeText(getContext(),"EXITO: "+tmpClientePago.getCliente().toString(),Toast.LENGTH_LONG).show();
  162. id_cxPay = tmpClientePago.getId_cliente().toString();
  163. namePay = tmpClientePago.getCliente().toString();
  164. vortPay = 0;
  165. debePay = tmpClientePago.getDeuda_total().toString();
  166. btnAgregarPago.setVisibility(View.VISIBLE);
  167. }
  168. }else {
  169. campoAddPago.setText("");
  170. campoAddDetailPago.setText("");
  171. cargarConsulta();
  172. }
  173. }
Add Comment
Please, Sign In to add comment