NonEMISummaryViewModel.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // NonEMISummaryViewModel.swift
  3. // Product Calculator
  4. //
  5. // Created by Suraj Kumar Mandal on 08/12/21.
  6. //
  7. import Foundation
  8. import Alamofire
  9. class NonEMISummaryViewModel {
  10. var delegate: NonEMISummaryViewProtocol?
  11. var nonEmiOutputList = [EMIOriginalLookupList]()
  12. //POST NON-EMI Output List
  13. func getNonEMIOutputList(begningBal:String, interestFrequency:String, refDate:String, loanEndDate:String, interestPaidAmount:String, totalMonths:String) {
  14. if let delegate = delegate {
  15. delegate.startLoader()
  16. let url = ApiUrl.BASE_URL + ApiUrl.GET_NON_EMI_LOAN_OUTPUT_LIST
  17. let parameters: [String: String] = [
  18. "begningBal": begningBal,
  19. "interestFrequency": interestFrequency,
  20. "refDate": refDate,
  21. "loanEndDate": loanEndDate,
  22. "interestPaidAmount": interestPaidAmount,
  23. "totalMonths": totalMonths
  24. ]
  25. print(parameters)
  26. AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
  27. switch response.result {
  28. case .success(let value):
  29. delegate.stopLoader()
  30. print(value)
  31. let data = value as! [NSDictionary]
  32. print(data)
  33. DispatchQueue.main.async {
  34. for item in data {
  35. let serialNumber = item["serialNumber"] as! Int
  36. let refDate = item["refDate"] as! String
  37. let financialYear = item["financialYear"] as! String
  38. let referenceMonth = item["referenceMonth"] as! String
  39. let installmentNumber = item["installmentNumber"] as! Int
  40. let begningBal = item["begningBal"] as! Double
  41. let interestPayment = item["interestPayment"] as! Double
  42. let principalPayment = item["principalPayment"] as! Double
  43. let endingBalance = item["endingBalance"] as! Double
  44. let emiAmount = item["emiAmount"] as! Double
  45. let totalPrincipalPaid = item["totalPrincipalPaid"] as! Double
  46. let totalInterestPaid = item["totalInterestPaid"] as! Double
  47. let loanEndDays = item["loanEndDays"] as! Int
  48. let displayDate = item["displayDate"] as! String
  49. let nonEmiOutputList = EMIOriginalLookupList(serialNumber: serialNumber, installmentNumber: installmentNumber, loanEndDays: loanEndDays, refDate: refDate, financialYear: financialYear, referenceMonth: referenceMonth, displayDate: displayDate, begningBal: begningBal, interestPayment: interestPayment, principalPayment: principalPayment, endingBalance: endingBalance, emiAmount: emiAmount, totalPrincipalPaid: totalPrincipalPaid, totalInterestPaid: totalInterestPaid)
  50. self.nonEmiOutputList.append(nonEmiOutputList)
  51. }
  52. }
  53. //delegate.navigate(bondModel: bondModel, bondOuputListModel: self.bondDebentureOutputListModel)
  54. case .failure(let error):
  55. delegate.stopLoader()
  56. print(error)
  57. //delegate.showError(error: error)
  58. }
  59. }
  60. }
  61. }
  62. }
  63. protocol NonEMISummaryViewProtocol {
  64. func startLoader()
  65. func stopLoader()
  66. func showError(error:String)
  67. func loadData(_ data:[EMIOriginalLookupList])
  68. }