EMILoanSummaryViewController.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // EMILoanSummaryViewController.swift
  3. // Product Calculator
  4. //
  5. // Created by Suraj Kumar Mandal on 07/12/21.
  6. //
  7. import UIKit
  8. import Toast_Swift
  9. class EMILoanSummaryViewController: UIViewController {
  10. @IBOutlet var label1: UILabel!
  11. @IBOutlet var textField1: UITextField!
  12. @IBOutlet var label2: UILabel!
  13. @IBOutlet var textField2: UITextField!
  14. @IBOutlet var label3: UILabel!
  15. @IBOutlet var textField3: UITextField!
  16. @IBOutlet var viewDetailedButton: UIButton!
  17. @IBOutlet var tableView: UITableView!
  18. var viewModel = EMILoanSummaryViewModel()
  19. var emiOriginalModel:EMILoanOriginalModel?
  20. var emiOutstandingModel:EMILoanOutstandingModel?
  21. var emiOriginalOutputList = [EMIOriginalLookupList]()
  22. var emiOutstandingOutputList = [EMIOutstandingLookupList]()
  23. var loanType = String()
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do any additional setup after loading the view.
  27. setupUI()
  28. setupData()
  29. }
  30. override func viewWillAppear(_ animated: Bool) {
  31. viewModel.delegate = self
  32. if loanType == "Original Loan Amount(Rs)" {
  33. viewModel.getEMIOriginalOutputList(numberOfEMI: String(emiOriginalModel!.numberOfEMI ?? 0), loanStartingDate: String(emiOriginalModel?.loanStartDate ?? ""), originalLoanAmount: String(emiOriginalModel?.loanAmount ?? 0), loanEMIAmt: String(emiOriginalModel?.emiAmount ?? 0), originalInterestRate: String(emiOriginalModel?.interestRate ?? 0), loanFlag: String(emiOriginalModel?.loan_original_flag ?? ""))
  34. } else {
  35. viewModel.getEMIOutstandingOutputList(numberOfEMI: String(emiOutstandingModel!.numberOfEMI ?? 0), loanStartingDate: String(emiOutstandingModel?.loanStartDate ?? ""), originalLoanAmount: String(emiOutstandingModel?.loanAmount ?? 0), loanEMIAmt: String(emiOutstandingModel?.emiAmount ?? 0), originalInterestRate: String(emiOutstandingModel?.interestRate ?? 0), loanFlag: String(emiOutstandingModel?.loan_original_flag ?? ""))
  36. }
  37. }
  38. func setupUI() {
  39. viewDetailedButton.isHidden = false
  40. tableView.isHidden = true
  41. }
  42. func setupData() {
  43. if loanType == "Original Loan Amount(Rs)" {
  44. label1.isHidden = false
  45. label2.isHidden = false
  46. label3.isHidden = false
  47. textField1.isHidden = false
  48. textField2.isHidden = false
  49. textField3.isHidden = false
  50. //Head label name
  51. label1.text = "No. of Original EMI Installments"
  52. label2.text = "Original EMI Amount(Rs)"
  53. label3.text = "Original Loan End Date"
  54. textField1.text = String(emiOriginalModel!.numberOfEMI!)
  55. textField2.text = String(format: "%.2f", "\(emiOriginalModel!.emiAmount!)")
  56. let date = emiOriginalModel!.loanEndDate
  57. let dateString = date?.stringBefore("T")
  58. textField3.text = convertDateFormat(inputDate: dateString!)
  59. } else {
  60. textField1.isHidden = false
  61. textField2.isHidden = false
  62. textField3.isHidden = true
  63. label1.isHidden = false
  64. label2.isHidden = false
  65. label3.isHidden = true
  66. //Head label name
  67. label1.text = "No. of Pending Installments"
  68. label2.text = "Current Loan End Date"
  69. textField1.text = String(emiOutstandingModel!.numberOfEMI!)
  70. let date = emiOriginalModel!.loanEndDate
  71. let dateString = date?.stringBefore("T")
  72. textField2.text = convertDateFormat(inputDate: dateString!)
  73. }
  74. }
  75. /*
  76. // MARK: - Navigation
  77. // In a storyboard-based application, you will often want to do a little preparation before navigation
  78. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  79. // Get the new view controller using segue.destination.
  80. // Pass the selected object to the new view controller.
  81. }
  82. */
  83. @IBAction func viewDetailedProjectionAction(_ sender: Any) {
  84. viewDetailedButton.isHidden = true
  85. tableView.isHidden = false
  86. }
  87. }
  88. extension EMILoanSummaryViewController : EMILoanSummaryViewProtocol {
  89. func startLoader() {
  90. ActivityIndicator.start()
  91. }
  92. func stopLoader() {
  93. ActivityIndicator.stop()
  94. }
  95. func showError(error: String) {
  96. self.view.makeToast(error)
  97. }
  98. func loadOriginal(_ data: [EMIOriginalLookupList]) {
  99. self.emiOriginalOutputList = data
  100. self.tableView.reloadData()
  101. }
  102. func loadOutstanding(_ data: [EMIOutstandingLookupList]) {
  103. self.emiOutstandingOutputList = data
  104. self.tableView.reloadData()
  105. }
  106. }
  107. extension EMILoanSummaryViewController : UITableViewDelegate, UITableViewDataSource {
  108. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  109. if loanType == "Original Loan Amount(Rs)" {
  110. return emiOriginalOutputList.count
  111. } else {
  112. return emiOutstandingOutputList.count
  113. }
  114. }
  115. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  116. let cell = tableView.dequeueReusableCell(withIdentifier: "EMILoanTableViewCell", for: indexPath) as? EMILoanTableViewCell
  117. if loanType == "Original Loan Amount(Rs)" {
  118. cell?.monthLabel.text = emiOriginalOutputList[indexPath.row].referenceMonth
  119. cell?.installmentNoLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].installmentNumber!)")
  120. cell?.beginningBalanceLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].begningBal!)")
  121. cell?.interestPaymentLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].interestPayment!)")
  122. cell?.principalPaymentLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].principalPayment!)")
  123. cell?.endingBalanceLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].endingBalance!)")
  124. cell?.emiAmountLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].emiAmount!)")
  125. cell?.totalPrincipalPaidToDateLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].totalPrincipalPaid!)")
  126. cell?.totalInterestPaidToDateLabel.text = String(format: "%.2f", "\(emiOriginalOutputList[indexPath.row].totalInterestPaid!)")
  127. } else {
  128. cell?.monthLabel.text = emiOutstandingOutputList[indexPath.row].referenceMonth
  129. cell?.installmentNoLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].installmentNumber!)")
  130. cell?.beginningBalanceLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].begningBal!)")
  131. cell?.interestPaymentLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].interestPayment!)")
  132. cell?.principalPaymentLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].principalPayment!)")
  133. cell?.endingBalanceLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].endingBalance!)")
  134. cell?.emiAmountLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].emiAmount!)")
  135. cell?.totalPrincipalPaidToDateLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].totalPrincipalPaid!)")
  136. cell?.totalInterestPaidToDateLabel.text = String(format: "%.2f", "\(emiOutstandingOutputList[indexPath.row].totalInterestPaid!)")
  137. }
  138. return cell!
  139. }
  140. }