123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // SukanyaSamriddhiViewModel.swift
- // Product Calculator
- //
- // Created by Suraj Kumar Mandal on 05/12/21.
- //
- import Foundation
- import Alamofire
- class SukanyaSamriddhiViewModel {
-
- var delegate: SukanyaSamriddhiViewProtocol?
-
- var sukanyaModel = [SukanyaSamriddhiModel]()
-
- //POST sukanya samriddhi Interest API
- func getInterestRate(depositDate:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_SUKANYA_SAMRIDDHI_INTEREST
-
- 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 PO recurring deposit API
- func getSukanyaSamriddhiOutput(depositAmount:String, tenureType:String, paymenttenure:String, rdDepositFreq:String, compundingFreq:String, depositDate:String, maturitytenure:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiUrl.BASE_URL + ApiUrl.GET_SUKANYA_SAMRIDDHI_OUTPUT
-
- var interest = String()
- switch compundingFreq {
- 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 = ""
- }
-
- var depositFrequency = String()
- switch rdDepositFreq {
- case "Monthly":
- depositFrequency = "12"
- case "Bi-Monthly":
- depositFrequency = "6"
- case "Quarterly":
- depositFrequency = "4"
- case "Triannually":
- depositFrequency = "3"
- case "Half Yearly":
- depositFrequency = "2"
- case "Annually":
- depositFrequency = "1"
- default:
- depositFrequency = ""
- }
-
- let parameters: [String: String] = [
- "deposit": depositAmount,
- "tenureType": tenureType,
- "paymenttenure": paymenttenure,
- "rdDepositFreq": depositFrequency,
- "compundingFreq": interest,
- "depositDate": depositDate,
- "maturitytenure": maturitytenure
- ]
- 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 depositAmount = data["depositAmount"] as! Double
- let amountDepositFreq = data["amountDepositFreq"] as! Int
- let annualInterest = data["annualInterest"] as! Double
- let term = data["term"] as! Int
- let compundFreq = data["compundFreq"] as! Double
- let depositDate = data["depositDate"] as? String
- let totalAmountDeposited = data["totalAmountDeposited"] as! Double
- let maturityAmount = data["maturityAmount"] as! Double
- let totalInterestReceived = data["totalInterestReceived"] as! Double
- let depositMaturityDate = data["depositMaturityDate"] as! String
- let paymentMaturityDate = data["paymentMaturityDate"] as! String
- let maturityDisplayDate = data["maturityDisplayDate"] as! String
- let paymentmaturityDisplayDate = data["paymentmaturityDisplayDate"] as! String
- let financialYear = data["financialYear"] as! String
- let interestRate = data["interestRate"] as! Double
-
- let sukanyaSamSchLookupList = data["sukanyaSamSchLookupList"] as! [NSDictionary]
-
- let sukanyaData = SukanyaSamriddhiModel(depositDate: depositDate ?? "", depositMaturityDate: depositMaturityDate, paymentMaturityDate: paymentMaturityDate, maturityDisplayDate: maturityDisplayDate, paymentmaturityDisplayDate: paymentmaturityDisplayDate, financialYear: financialYear, amountDepositFreq: amountDepositFreq, term: term, depositAmount: depositAmount, annualInterest: annualInterest, compundFreq: compundFreq, totalAmountDeposited: totalAmountDeposited, maturityAmount: maturityAmount, totalInterestReceived: totalInterestReceived, interestRate: interestRate)
-
- for list in sukanyaSamSchLookupList {
- 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 openingBal = list.value(forKey: "openingBal") as! Double
- let amountDeposited = list.value(forKey: "amountDeposited") as! Double
- let interestAccrued = list.value(forKey: "interestAccrued") as! Double
- let interestCredited = list.value(forKey: "interestCredited") as! Double
- let interestRate = list.value(forKey: "interestRate") as! Double
- let totalInterestAccrued = list.value(forKey: "totalInterestAccrued") as! Double
- let closingBalance = list.value(forKey: "closingBalance") as! Double
- let daysToMaturity = list.value(forKey: "daysToMaturity") as! NSNumber
-
- let list = SukanyaSamriddhiLookupList(serialNo: Int(truncating: serialNo), daysToMaturity: Int(truncating: daysToMaturity), referenceDate: referenceDate, referenceMonth: referenceMonth, financialYear: financialYear, openingBal: openingBal, amountDeposited: amountDeposited, interestAccrued: interestAccrued, interestCredited: interestCredited, totalInterestAccrued: totalInterestAccrued, closingBalance: closingBalance, interestRate: interestRate)
-
- sukanyaData.sukanyaSamSchLookupList.append(list)
- }
- self.sukanyaModel.append(sukanyaData)
- delegate.navigate(sukanyaData)
- }
-
- case .failure(let error):
- delegate.stopLoader()
- print(error)
- //delegate.showError(error: error)
- }
- }
- }
- }
-
- }
- protocol SukanyaSamriddhiViewProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func setInterestRate(rate:String)
- func navigate(_ data:SukanyaSamriddhiModel)
- }
|