123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // EPFViewModel.swift
- // Product Calculator
- //
- // Created by Suraj Kumar Mandal on 08/12/21.
- //
- import Foundation
- import Alamofire
- class EPFViewModel {
-
- var delegate: EPFViewProtocol?
-
- var epfModel = [EPFModel]()
-
- //POST EPF Interest Rate API
- func getInterestRate() {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EPF_INTEREST_RATE
-
- AF.request(url, method: .get, 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 interestRate = data["interestRate"] as! Double
-
- delegate.setInterestRate(rate: String(interestRate))
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST EPF Growth Rate API
- func getGrowthRate() {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EPF_GROWTH_RATE
-
- AF.request(url, method: .get, 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 interestRate = data["interestRate"] as! Double
-
- delegate.setGrowthRate(rate: String(interestRate))
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST EPF API
- func getEPFOutput(clientDOB:String, currEPFBal:String, currEPSBal:String, monthlyBasicDA:String, expectedIncreaseSal:String, contributionUptoAge:String, epfWithdrawAlage:String, increaseMonth:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_EPF_DETAILS
-
- let parameters: [String: String] = [
- "clientDOB": clientDOB,
- "currEPFBal": currEPFBal,
- "currEPSBal": currEPSBal,
- "monthlyBasicDA": monthlyBasicDA,
- "expectedIncreaseSal": expectedIncreaseSal,
- "contributionUptoAge": contributionUptoAge,
- "epfWithdrawAlage": epfWithdrawAlage,
- "increaseMonth": increaseMonth,
- ]
- 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 clientDOB = data["clientDOB"] as? String
- let currEPF = data["currEPF"] as! Double
- let currEPS = data["currEPS"] as! Double
- let monBasicDA = data["monBasicDA"] as! Double
- let expSalInc = data["expSalInc"] as! Double
- let expEPFO = data["expEPFO"] as! Double
- let conUptoAge = data["conUptoAge"] as! Int
- let epfWiDAge = data["epfWiDAge"] as! Int
- let planDate = data["planDate"] as? String
- let salIncreaseMonth = data["salIncreaseMonth"] as! Int
- let epfBalWithdraw = data["epfBalWithdraw"] as! Double
- let epsBalClientAge = data["epsBalClientAge"] as! Double
- let totalInterestEarned = data["totalInterestEarned"] as! Double
- let employeeCont = data["employeeCont"] as! Double
- let employerCont = data["employerCont"] as! Double
- let currentInterestRate = data["currentInterestRate"] as! Double
-
- let lookupList = data["lookupList"] as! [NSDictionary]
-
- let epfData = EPFModel(conUptoAge: conUptoAge, epfWiDAge: epfWiDAge, salIncreaseMonth: salIncreaseMonth, currEPF: currEPF, currEPS: currEPS, monBasicDA: monBasicDA, expSalInc: expSalInc, expEPFO: expEPFO, epfBalWithdraw: epfBalWithdraw, epsBalClientAge: epsBalClientAge, totalInterestEarned: totalInterestEarned, employeeCont: employeeCont, employerCont: employerCont, currentInterestRate: currentInterestRate)
-
- for list in lookupList {
- let serialNumber = list.value(forKey: "serialNumber") as! NSNumber
- let refDate = list.value(forKey: "refDate") as! String
- let financialYear = list.value(forKey: "financialYear") as! String
- let referenceMonth = list.value(forKey: "referenceMonth") as! String
- let clientAge = list.value(forKey: "clientAge") as! Int
- let monBasicDA = list.value(forKey: "monBasicDA") as! Double
- let openingBalEPF = list.value(forKey: "openingBalEPF") as! Double
- let openingBalEPS = list.value(forKey: "openingBalEPS") as! Double
- let employeeContEPF = list.value(forKey: "employeeContEPF") as! Double
- let employerContEPF = list.value(forKey: "employerContEPF") as! Double
- let employerContEPS = list.value(forKey: "employerContEPS") as! Double
- let interestRateEPF = list.value(forKey: "interestRateEPF") as! Double
- let interestEarnedEPF = list.value(forKey: "interestEarnedEPF") as! Double
- let totalInterestEarnedEPF = list.value(forKey: "totalInterestEarnedEPF") as! Double
- let closingBalEPF = list.value(forKey: "closingBalEPF") as! Double
- let closingBalEPS = list.value(forKey: "closingBalEPS") as! Double
- let displayDate = list.value(forKey: "displayDate") as! String
-
- let list = EPFLookupList(serialNumber: Int(truncating: serialNumber), clientAge: clientAge, refDate: refDate, financialYear: financialYear, referenceMonth: referenceMonth, displayDate: displayDate, monBasicDA: monBasicDA, openingBalEPF: openingBalEPF, openingBalEPS: openingBalEPS, employeeContEPF: employeeContEPF, employerContEPF: employerContEPF, employerContEPS: employerContEPS, interestRateEPF: interestRateEPF, interestEarnedEPF: interestEarnedEPF, totalInterestEarnedEPF: totalInterestEarnedEPF, closingBalEPF: closingBalEPF, closingBalEPS: closingBalEPS)
-
- epfData.lookupList.append(list)
- }
- self.epfModel.append(epfData)
- delegate.navigate(epfData)
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- }
- protocol EPFViewProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func setInterestRate(rate:String)
- func setGrowthRate(rate:String)
- func navigate(_ data:EPFModel)
- }
|