123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // EMILoanSummaryViewModel.swift
- // Product Calculator
- //
- // Created by Suraj Kumar Mandal on 07/12/21.
- //
- import Foundation
- import Alamofire
- class EMILoanSummaryViewModel {
-
- var delegate: EMILoanSummaryViewProtocol?
-
- var emiOriginalOutputList = [EMIOriginalLookupList]()
- var emiOutstandingOutputList = [EMIOutstandingLookupList]()
-
- //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_BOND_DEBENTURE_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.loadOriginal(self.emiOriginalOutputList)
-
- 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_BOND_DEBENTURE_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.loadOutstanding(self.emiOutstandingOutputList)
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- }
- protocol EMILoanSummaryViewProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func loadOriginal(_ data:[EMIOriginalLookupList])
- func loadOutstanding(_ data:[EMIOutstandingLookupList])
- }
|