123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // EMILoanViewModel.swift
- // Product Calculator
- //
- // Created by Suraj Kumar Mandal on 01/12/21.
- //
- import Foundation
- import Alamofire
- class EMILoanViewModel {
-
- var delegate: EMILoanViewProtocol?
-
- var emiOriginalModel = [EMILoanOriginalModel]()
- var emiOriginalOutputList = [EMIOriginalLookupList]()
- var emiOutstandingModel = [EMILoanOutstandingModel]()
- var emiOutstandingOutputList = [EMIOutstandingLookupList]()
-
- //POST EMI Original API
- func getEMIOriginalLoan(loanFlag:String, originalInterestRate:String, originalLoanAmount:String, loanStartDate:String, loanTenure:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EMI_LOAN
-
- let parameters: [String: String] = [
- "loanFlag": loanFlag,
- "originalInterestRate": originalInterestRate,
- "originalLoanAmount": originalLoanAmount,
- "loanStartDate": loanStartDate,
- "loanTenure": loanTenure
- ]
- print(parameters)
-
- AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
-
- switch response.result {
- case .success(let value):
- delegate.stopLoader()
- print(value)
- let data = value as! NSDictionary
- print(data)
- DispatchQueue.main.async {
- let loanCategory = data["loanCategory"] as? Int
- let loanCategoryLabel = data["loanCategoryLabel"] as? String
- let loanDiscription = data["loanDiscription"] as? String
- let loanProvider = data["loanProvider"] as? String
- let loanType = data["loanType"] as! Int
- let loanTypeLabel = data["loanTypeLabel"] as? String
- let loanAmount = data["loanAmount"] as! Double
- let interestRate = data["interestRate"] as! Double
- let loanTenure = data["loanTenure"] as! Int
- let loanStartDate = data["loanStartDate"] as? String
- let numberOfEMI = data["numberOfEMI"] as! Int
- let emiAmount = data["emiAmount"] as! Double
- let loanEndDate = data["loanEndDate"] as! String
- let interestPaymentFrequency = data["interestPaymentFrequency"] as! Int
- let totalInterestPaid = data["totalInterestPaid"] as! Double
- let loan_original_flag = data["loan_original_flag"] as? String
- let displayDate = data["displayDate"] as? String
-
- let emiOriginalData = EMILoanOriginalModel(loanCategoryLabel: loanCategoryLabel ?? "", loanDiscription: loanDiscription ?? "", loanProvider: loanProvider ?? "", loanTypeLabel: loanTypeLabel ?? "", loanStartDate: loanStartDate ?? "", loanEndDate: loanEndDate, loan_original_flag: loan_original_flag ?? "", displayDate: displayDate ?? "", loanCategory: loanCategory ?? 0, loanType: loanType, loanTenure: loanTenure, numberOfEMI: numberOfEMI, interestPaymentFrequency: interestPaymentFrequency, loanAmount: loanAmount, interestRate: interestRate, emiAmount: emiAmount, totalInterestPaid: totalInterestPaid)
-
- self.emiOriginalModel.append(emiOriginalData)
- delegate.navigateOriginal(emiOriginalData)
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST EMI Original Output List
- func getEMIOriginalOutputList(numberOfEMI:String, loanStartingDate:String, originalLoanAmount:String, loanEMIAmt:String, originalInterestRate:String, loanFlag:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EMI_LOAN_OUTPUT_LIST
-
- let parameters: [String: String] = [
- "numberOfEMI": numberOfEMI,
- "loanStartingDate": loanStartingDate,
- "originalLoanAmount": originalLoanAmount,
- "loanEMIAmt": loanEMIAmt,
- "originalInterestRate": originalInterestRate,
- "loanFlag": loanFlag
- ]
- print(parameters)
-
- AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
-
- switch response.result {
- case .success(let value):
- delegate.stopLoader()
- print(value)
- let data = value as! [NSDictionary]
- print(data)
- DispatchQueue.main.async {
- for item in data {
- let serialNumber = item["serialNumber"] as! Int
- let refDate = item["refDate"] as! String
- let financialYear = item["financialYear"] as! String
- let referenceMonth = item["referenceMonth"] as! String
- let installmentNumber = item["installmentNumber"] as! Int
- let begningBal = item["begningBal"] as! Double
- let interestPayment = item["interestPayment"] as! Double
- let principalPayment = item["principalPayment"] as! Double
- let endingBalance = item["endingBalance"] as! Double
- let emiAmount = item["emiAmount"] as! Double
- let totalPrincipalPaid = item["totalPrincipalPaid"] as! Double
- let totalInterestPaid = item["totalInterestPaid"] as! Double
- let loanEndDays = item["loanEndDays"] as! Int
- let displayDate = item["displayDate"] as! String
-
- let emiOriginalOutputList = 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)
- self.emiOriginalOutputList.append(emiOriginalOutputList)
- }
- }
- //delegate.navigate(bondModel: bondModel, bondOuputListModel: self.bondDebentureOutputListModel)
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST EMI Outstanding API
- func getEMIOutstandingLoan(loanFlag:String, originalInterestRate:String, originalLoanAmount:String, loanDayout:String, loanEMIAmt:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EMI_LOAN
-
- let parameters: [String: String] = [
- "loanFlag": loanFlag,
- "originalInterestRate": originalInterestRate,
- "originalLoanAmount": originalLoanAmount,
- "loanDayout": loanDayout,
- "loanEMIAmt": loanEMIAmt
- ]
- print(parameters)
-
- AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
-
- switch response.result {
- case .success(let value):
- delegate.stopLoader()
- print(value)
- let data = value as! NSDictionary
- print(data)
- DispatchQueue.main.async {
- let loanCategory = data["loanCategory"] as? Int
- let loanCategoryLabel = data["loanCategoryLabel"] as? String
- let loanDiscription = data["loanDiscription"] as? String
- let loanProvider = data["loanProvider"] as? String
- let loanType = data["loanType"] as? Int
- let loanTypeLabel = data["loanTypeLabel"] as? String
- let loanAmount = data["loanAmount"] as! Double
- let interestRate = data["interestRate"] as! Double
- let loanTenure = data["loanTenure"] as! Int
- let loanStartDate = data["loanStartDate"] as? String
- let numberOfEMI = data["numberOfEMI"] as! Int
- let emiAmount = data["emiAmount"] as! Double
- let loanEndDate = data["loanEndDate"] as! String
- let interestPaymentFrequency = data["interestPaymentFrequency"] as! Int
- let totalInterestPaid = data["totalInterestPaid"] as! Double
- let loan_original_flag = data["loan_original_flag"] as? String
- let displayDate = data["displayDate"] as? String
-
- let emiOutstandingData = EMILoanOutstandingModel(loanCategoryLabel: loanCategoryLabel ?? "", loanDiscription: loanDiscription ?? "", loanProvider: loanProvider ?? "", loanTypeLabel: loanTypeLabel ?? "", loanStartDate: loanStartDate ?? "", loanEndDate: loanEndDate, loan_original_flag: loan_original_flag ?? "", displayDate: displayDate ?? "", loanCategory: loanCategory ?? 0, loanType: loanType ?? 0, loanTenure: loanTenure, numberOfEMI: numberOfEMI, interestPaymentFrequency: interestPaymentFrequency, loanAmount: loanAmount, interestRate: interestRate, emiAmount: emiAmount, totalInterestPaid: totalInterestPaid)
-
- self.emiOutstandingModel.append(emiOutstandingData)
- //delegate.navigate(cpcdData)
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST EMI Outstanding Output List
- func getEMIOutstandingOutputList(numberOfEMI:String, loanStartingDate:String, originalLoanAmount:String, loanEMIAmt:String, originalInterestRate:String, loanFlag:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EMI_LOAN_OUTPUT_LIST
-
- let parameters: [String: String] = [
- "numberOfEMI": numberOfEMI,
- "loanStartingDate": loanStartingDate,
- "originalLoanAmount": originalLoanAmount,
- "loanEMIAmt": loanEMIAmt,
- "originalInterestRate": originalInterestRate,
- "loanFlag": loanFlag
- ]
- print(parameters)
-
- AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
-
- switch response.result {
- case .success(let value):
- delegate.stopLoader()
- print(value)
- let data = value as! [NSDictionary]
- print(data)
- DispatchQueue.main.async {
- for item in data {
- let serialNumber = item["serialNumber"] as! Int
- let refDate = item["refDate"] as! String
- let financialYear = item["financialYear"] as! String
- let referenceMonth = item["referenceMonth"] as! String
- let installmentNumber = item["installmentNumber"] as! Int
- let begningBal = item["begningBal"] as! Double
- let interestPayment = item["interestPayment"] as! Double
- let principalPayment = item["principalPayment"] as! Double
- let endingBalance = item["endingBalance"] as! Double
- let emiAmount = item["emiAmount"] as! Double
- let totalPrincipalPaid = item["totalPrincipalPaid"] as! Double
- let totalInterestPaid = item["totalInterestPaid"] as! Double
- let loanEndDays = item["loanEndDays"] as! Int
- let displayDate = item["displayDate"] as! String
-
- let emiOutstandingOutputList = EMIOutstandingLookupList(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)
- self.emiOutstandingOutputList.append(emiOutstandingOutputList)
- }
- }
- //delegate.navigate(bondModel: bondModel, bondOuputListModel: self.bondDebentureOutputListModel)
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- }
- protocol EMILoanViewProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func navigateOriginal(_ data:EMILoanOriginalModel)
- func navigateOutstanding(_ data:EMILoanOutstandingModel)
- }
|