You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // TransactionHistoryPresenter.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/09/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class TransactionHistoryPresenter {
  10. // MARK: Properties
  11. var models: [TransactionModel] = []
  12. var filteredModels: [TransactionModel] = [] {
  13. didSet {
  14. self.view?.show(models: filteredModels)
  15. }
  16. }
  17. weak var view: TransactionHistoryViewInterface?
  18. var interactor: TransactionHistoryInteractorInput?
  19. var wireframe: TransactionHistoryWireframeInput?
  20. // MARK: Converting entities
  21. }
  22. // MARK: TransactionHistory module interface
  23. extension TransactionHistoryPresenter: TransactionHistoryModuleInterface {
  24. func fetchTransactionHistories(fromDate: String?, toDate: String?) {
  25. self.view?.showLoading()
  26. interactor?.fetchTransactionHistories(fromDate: fromDate, toDate: toDate)
  27. }
  28. func viewIsReady() {
  29. self.fetchTransactionHistories(fromDate: nil, toDate: nil)
  30. }
  31. func filterTransaction(type: TransactionModelType) {
  32. switch type {
  33. case .all:
  34. self.filteredModels = models
  35. case .paid:
  36. self.filteredModels = models.filter({
  37. ($0.payStatus ?? "" ) == type.rawValue
  38. })
  39. case .received:
  40. self.filteredModels = models.filter({
  41. ($0.payStatus ?? "" ) != TransactionModelType.paid.rawValue
  42. })
  43. }
  44. }
  45. func showDetailOf(index: Int) {
  46. let element = self.models.elementAt(index: index)
  47. guard let id = element?.transactionId, let controlNo = element?.controlNumber else {return}
  48. wireframe?.openReciept(transactionId: id, control: controlNo)
  49. }
  50. func search(text: String) {
  51. let searchText = text.lowercased()
  52. self.filteredModels = (models).filter({
  53. model in
  54. return searchText.isEmpty || (model.controlNumber ?? "").contains(searchText)
  55. })
  56. // self.filteredModels = (models).filter({
  57. // model in
  58. // return searchText.isEmpty || (model.user ?? "").lowercased().contains(searchText)
  59. // }).sorted(by: { (model, _) -> Bool in
  60. // return (model.user ?? "").hasPrefix(searchText)
  61. // })
  62. }
  63. }
  64. // MARK: TransactionHistory interactor output interface
  65. extension TransactionHistoryPresenter: TransactionHistoryInteractorOutput {
  66. func show(error: Error) {
  67. self.view?.hideLoading()
  68. self.view?.show(error: error.localizedDescription)
  69. }
  70. func show(models: [TransactionModel]) {
  71. self.view?.hideLoading()
  72. self.models = models
  73. self.filteredModels = self.models
  74. }
  75. }