saldos_provider.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'dart:convert';
  2. import '../models/saldos_cartera.dart' as cartera;
  3. import '../models/saldos_contacto.dart';
  4. import 'package:http/http.dart' as http;
  5. class SaldosProvider{
  6. final String _url = "smart.solerpalau.mx";
  7. Future<SaldosContacto> fetchSaldosContacto(String token) async{
  8. final url = Uri.https(_url, 'PR/api/v1/quiosco/saldos/obtenerDatosContacto');
  9. final res = await http.post(url,
  10. headers: {
  11. 'Authorization' : 'Bearer $token'
  12. }
  13. );
  14. final decodedData = jsonDecode(res.body);
  15. final saldosContacto = SaldosContacto.fromJson(decodedData);
  16. return saldosContacto;
  17. }
  18. Future<cartera.SaldosCartera> fetchSaldosCartera(String token, String dinum, String dinombre) async{
  19. final url = Uri.https(_url, 'PR/api/v1/quiosco/saldos/obtenerCartera');
  20. final res = await http.post(url,
  21. headers: {
  22. 'Authorization' : 'Bearer $token'
  23. },
  24. body: {
  25. 'DINUM' : '$dinum',
  26. 'DINOMBRE' : '$dinombre'
  27. }
  28. );
  29. final decodedData = jsonDecode(res.body);
  30. if(decodedData['result']['registros'].isEmpty && decodedData['result']['datosGenerales'].isEmpty){
  31. return cartera.SaldosCartera(
  32. result: cartera.Result(
  33. carteraVencer: {},
  34. datosGenerales: cartera.DatosGenerales(
  35. mxp: cartera.Mxp(
  36. moneda: '',
  37. totalCartera: '',
  38. totalCarteraVencida: '',
  39. totalCarteraVencer: '',
  40. pendientePorAplicar: '',
  41. total: '',
  42. ),
  43. usd: cartera.Usd(
  44. moneda: '',
  45. totalCartera: '',
  46. totalCarteraVencida: '',
  47. totalCarteraVencer: '',
  48. pendientePorAplicar: '',
  49. total: '',
  50. ),
  51. ),
  52. registros: [],
  53. ),
  54. message: '',
  55. response: false,
  56. );
  57. }
  58. final saldosCartera = cartera.SaldosCartera.fromJson(decodedData);
  59. return saldosCartera;
  60. }
  61. }