123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // SeniorCitizenSavingViewModel.swift
- // Product Calculator
- //
- // Created by Suraj Kumar Mandal on 05/12/21.
- //
- import Foundation
- import Alamofire
- class SeniorCitizenSavingViewModel {
-
- var delegate: SeniorCitizenSavingViewProtocol?
-
- var scssModel = [SeniorCitizenSavingModel]()
-
- //POST SCSS Interest API
- func getInterestRate(depositDate:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_SCSS_INTEREST_RATE
-
- let parameters: [String: String] = [
- "depositDate": depositDate
- ]
- 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 interestRate = data["interestRate"] as! Double
-
- delegate.setInterestRate(rate: String(interestRate))
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- //POST SCSS API
- func getSCSSOutput(depositAmount:String, years:String, interestFrequency:String, depositDate:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_SCSS_OUTPUT
-
- var interest = String()
- switch interestFrequency {
- case "Monthly":
- interest = "12"
- case "Bi-Monthly":
- interest = "6"
- case "Quarterly":
- interest = "4"
- case "Triannually":
- interest = "3"
- case "Half Yearly":
- interest = "2"
- case "Annually":
- interest = "1"
- default:
- interest = ""
- }
-
- let parameters: [String: String] = [
- "deposit": depositAmount,
- "years": years,
- "interestFrequency": interest,
- "depositDate": depositDate
- ]
- 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 maturityDisplayDate = data["maturityDisplayDate"] as? String
- let interestRate = data["interestRate"] as! Double
- let interestReceived = data["interestReceived"] as! Double
- let totalInterestReceived = data["totalInterestReceived"] as! Double
- let maturityDate = data["maturityDate"] as! String
-
- let seniorCitizenSavingSchemeLookupsList = data["seniorCitizenSavingSchemeLookupsList"] as! [NSDictionary]
-
- let scssData = SeniorCitizenSavingModel(maturityDate: maturityDate, maturityDisplayDate: maturityDisplayDate ?? "", interestReceived: interestReceived, totalInterestReceived: totalInterestReceived, interestRate: interestRate)
-
- for list in seniorCitizenSavingSchemeLookupsList {
- let serialNo = list.value(forKey: "serialNo") as! NSNumber
- let referenceDate = list.value(forKey: "referenceDate") as! String
- let referenceMonth = list.value(forKey: "referenceMonth") as! String
- let financialYear = list.value(forKey: "financialYear") as! String
- let amountDeposited = list.value(forKey: "amountDeposited") as! Double
- let interestReceived = list.value(forKey: "interestReceived") as! Double
- let totalInterestReceived = list.value(forKey: "totalInterestReceived") as! Double
- let daysToMaturity = list.value(forKey: "daysToMaturity") as! NSNumber
-
- let list = SCSSLookupList(serialNo: Int(truncating: serialNo), amountDeposited: amountDeposited, totalInterestReceived: totalInterestReceived, interestReceived: interestReceived, daysToMaturity: Int(truncating: daysToMaturity), referenceDate: referenceDate, referenceMonth: referenceMonth, financialYear: financialYear)
-
- scssData.seniorCitizenSavingSchemeLookupsList.append(list)
- }
- self.scssModel.append(scssData)
- delegate.navigate(scssData)
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- }
- protocol SeniorCitizenSavingViewProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func setInterestRate(rate:String)
- func navigate(_ data:SeniorCitizenSavingModel)
- }
|