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.

668 lines
30 KiB

6 years ago
  1. //
  2. // TranscationStatementViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by FMI-12 on 2/6/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class TranscationStatementViewController: UIViewController,TableViewCellTransactionDelegate {
  10. @IBOutlet weak var tableViewTranscation: UITableView!
  11. @IBOutlet weak var segmentedControl: UISegmentedControl!
  12. private var selectedTransaction: Transaction?
  13. private var tracktransactionviewmodel = TrackTransactionViewModel()
  14. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  15. private var transactionCell: TranscationTableViewCell?
  16. private var loadMoreButtonOutlet:UIButton?
  17. private var status: Bool?
  18. private var segment: String = "all"
  19. private var allSize: Int = 20
  20. private var allPage: Int = 0
  21. private var receivedPage: Int = 0
  22. private var sentPage: Int = 0
  23. private var allTransaction = [Transaction]()
  24. private var sentTransaction = [Transaction]()
  25. private var receivedTransaction = [Transaction]()
  26. public var fromNotification: Int?
  27. public static var notificationCode: String = ""
  28. let pNotificationArray = ["p200","p203","p206","p207","p204", "p208"]
  29. public static var transactionConnectionTimeOutCheck = 0
  30. override func viewDidAppear(_ animated: Bool) {
  31. setUpAnotherLoginListener(genericviewmodel: tracktransactionviewmodel)
  32. }
  33. override func viewDidLoad() {
  34. super.viewDidLoad()
  35. if pNotificationArray.contains(TranscationStatementViewController.notificationCode) {
  36. setUpNavBar(id: 207, title: "Transaction Statement")
  37. }else {
  38. setUpNavBar(id: 201, title: "Transaction Statement")
  39. }
  40. selectedSegmentControlTab()
  41. TranscationStatementViewController.notificationCode.removeAll()
  42. self.tableViewTranscation.delegate = self
  43. self.tableViewTranscation.dataSource = self
  44. self.tableViewTranscation.estimatedRowHeight = 119
  45. self.tableViewTranscation.rowHeight = UITableViewAutomaticDimension
  46. self.tableViewTranscation.tableFooterView = UIView()
  47. segmentedControl.addTarget(self, action: #selector(transactionTypeChanged(_:)), for: .valueChanged)
  48. tracktransactionviewmodel.transactionListConnectionTimeOut.value = nil
  49. /**
  50. connection timeout
  51. */
  52. tracktransactionviewmodel.transactionListConnectionTimeOut.bind { [unowned self] in
  53. guard $0 != nil else {
  54. return
  55. }
  56. self.stopLoading()
  57. if self.fromNotification != 0{
  58. if TranscationStatementViewController.transactionConnectionTimeOutCheck == 0{
  59. TranscationStatementViewController.transactionConnectionTimeOutCheck = TranscationStatementViewController.transactionConnectionTimeOutCheck+1
  60. self.popUpMessage(value: 30)
  61. }
  62. }
  63. self.clearAllArray()
  64. self.tableViewTranscation.reloadData()
  65. self.loadMoreButtonOutlet?.isHidden = true
  66. }
  67. /**
  68. Check internet connection
  69. */
  70. tracktransactionviewmodel.internetConnection.value = nil
  71. tracktransactionviewmodel.internetConnection.bind { [unowned self] in
  72. guard $0 != nil else {
  73. return
  74. }
  75. self.stopLoading()
  76. self.popUpMessage(value: 15)
  77. self.clearAllArray()
  78. self.tableViewTranscation.reloadData()
  79. self.loadMoreButtonOutlet?.isHidden = true
  80. }
  81. /**
  82. Request user all transactions
  83. */
  84. self.startLoading()
  85. tracktransactionviewmodel.transactionListObtained.bind{ [unowned self] in
  86. guard $0 != nil else {
  87. return
  88. }
  89. guard $0! else {
  90. self.stopLoading()
  91. if TranscationStatementViewController.transactionConnectionTimeOutCheck == 0{
  92. TranscationStatementViewController.transactionConnectionTimeOutCheck = TranscationStatementViewController.transactionConnectionTimeOutCheck+1
  93. self.popUpMessageError(value: 10, message: self.tracktransactionviewmodel.getErrorMessage())
  94. }
  95. return
  96. }
  97. self.stopLoading()
  98. if self.tracktransactionviewmodel.getCount() > 0{
  99. self.loadTableView()
  100. }else{
  101. self.loadTableView()
  102. }
  103. }
  104. switch segmentedControl.selectedSegmentIndex {
  105. case 1:
  106. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
  107. case 2:
  108. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
  109. default:
  110. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
  111. }
  112. }
  113. @IBAction func actionSearch(_ sender: Any) {
  114. status = true
  115. self.performSegue(withIdentifier: "searchTransaction", sender: nil)
  116. }
  117. @IBAction func actionCalendarView(_ sender: Any) {
  118. status = false
  119. self.performSegue(withIdentifier: "searchTransaction", sender: nil)
  120. }
  121. /**
  122. Remove all array
  123. */
  124. func clearAllArray(){
  125. allTransaction.removeAll()
  126. sentTransaction.removeAll()
  127. receivedTransaction.removeAll()
  128. }
  129. /**
  130. Redirect to segment as per the notification type
  131. */
  132. func selectedSegmentControlTab(){
  133. switch TranscationStatementViewController.notificationCode {
  134. case "204", "208","p204", "p208":
  135. segment = "received"
  136. segmentedControl.selectedSegmentIndex = 1
  137. case "200","203","206","207","p200","p203","p206","p207":
  138. segment = "sent"
  139. segmentedControl.selectedSegmentIndex = 2
  140. default:
  141. segment = "all"
  142. segmentedControl.selectedSegmentIndex = 0
  143. }
  144. }
  145. /**
  146. Append more transactions data into global array and reload tableview
  147. */
  148. func loadTableView(){
  149. self.tableViewTranscation.isHidden = false
  150. switch self.segment {
  151. case "all":
  152. allTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
  153. if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
  154. self.loadMoreButtonOutlet?.isHidden = false
  155. }else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
  156. self.loadMoreButtonOutlet?.isHidden = true
  157. }
  158. case "received":
  159. receivedTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
  160. if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
  161. self.loadMoreButtonOutlet?.isHidden = false
  162. }else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
  163. self.loadMoreButtonOutlet?.isHidden = true
  164. }
  165. case "sent":
  166. sentTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
  167. if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
  168. self.loadMoreButtonOutlet?.isHidden = false
  169. }else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
  170. self.loadMoreButtonOutlet?.isHidden = true
  171. }
  172. default:
  173. break
  174. }
  175. self.tableViewTranscation.reloadData()
  176. self.tableViewStartFromBeginningRow()
  177. }
  178. /**
  179. Show tableview from 0 index
  180. */
  181. func tableViewStartFromBeginningRow(){
  182. switch segment {
  183. case "all":
  184. if (allTransaction.count > 0){
  185. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  186. }
  187. case "received":
  188. if (receivedTransaction.count>0){
  189. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  190. }
  191. case "sent":
  192. if (sentTransaction.count>0){
  193. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  194. }
  195. default:
  196. break
  197. }
  198. }
  199. /**
  200. Request when user wants to view old transactions
  201. */
  202. @objc func loadMoreButtonAction(sender: TranscationTableViewCell) {
  203. self.startLoading()
  204. switch segment {
  205. case "all":
  206. self.allPage = self.allPage+1
  207. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
  208. case "received":
  209. self.receivedPage = self.receivedPage+1
  210. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: self.receivedPage, size: self.allSize)
  211. case "sent":
  212. self.sentPage = self.sentPage+1
  213. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: self.sentPage, size: self.allSize)
  214. default :
  215. break
  216. }
  217. }
  218. /**
  219. Check whether transaction type is sent or received
  220. - Parameter payoutMode: the type of payout mode are like cash,bank,topup door to dorr and withdraw.
  221. - Parameter transferType: the type of transferType are like offer and request.
  222. - Returns : transactions type is sent or received
  223. */
  224. // func checkSentOrReceive(payoutMode: String, userId: String?) -> String {
  225. // if(payoutMode.caseInsensitiveCompare("cash") == ComparisonResult.orderedSame ||
  226. // payoutMode.caseInsensitiveCompare("bank") == ComparisonResult.orderedSame ||
  227. // payoutMode.caseInsensitiveCompare("topup") == ComparisonResult.orderedSame ||
  228. // payoutMode.caseInsensitiveCompare("Door to Door") == ComparisonResult.orderedSame ||
  229. // payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
  230. // return "sent"
  231. // }else if (payoutMode.caseInsensitiveCompare("wallet Transfer") == ComparisonResult.orderedSame){
  232. // let selfUserId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
  233. //
  234. // if userId != nil {
  235. // if userId == selfUserId! {
  236. // return "sent"
  237. // }
  238. // return "received"
  239. // }
  240. // }
  241. // return "received"
  242. // }
  243. /**
  244. Disable user interaction while fetching data from api
  245. */
  246. func startLoading(){
  247. tableViewTranscation.isHidden = true
  248. disableUserInteractions()
  249. showActivityIndicator(activityIndicator: activityIndicator)
  250. }
  251. /**
  252. Enable user interaction while fetching data from api
  253. */
  254. func stopLoading(){
  255. tableViewTranscation.isHidden = false
  256. enableUserInteractions()
  257. dismissActivityIndicator(activityIndicator: activityIndicator)
  258. }
  259. /**
  260. Show load more button if only transaction count value is greater than 20
  261. - Parameter segment: UI have three different segment i.e. All, Received and Sent
  262. */
  263. func checkLoadingMoreVisible(segment: String){
  264. switch segment {
  265. case "all":
  266. if allTransaction.count >= self.allSize{
  267. loadMoreButtonOutlet?.isHidden = false
  268. }else{
  269. loadMoreButtonOutlet?.isHidden = true
  270. }
  271. case "received":
  272. if receivedTransaction.count >= self.allSize{
  273. loadMoreButtonOutlet?.isHidden = false
  274. }else{
  275. loadMoreButtonOutlet?.isHidden = true
  276. }
  277. case "sent":
  278. if sentTransaction.count >= self.allSize{
  279. loadMoreButtonOutlet?.isHidden = false
  280. }else{
  281. loadMoreButtonOutlet?.isHidden = true
  282. }
  283. default:
  284. break
  285. }
  286. }
  287. /**
  288. Action handle when user switch between three different segment i.e. All , Received and Sent
  289. */
  290. @objc func transactionTypeChanged(_ segControl: UISegmentedControl) {
  291. switch segControl.selectedSegmentIndex {
  292. case 0:
  293. self.segment = "all"
  294. ///To display list from first page only When tap to all segmentControl
  295. allPage = 0
  296. if allTransaction.count == 0 {
  297. startLoading()
  298. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil, page: allPage, size: allSize)
  299. }else{
  300. stopLoading()
  301. tableViewTranscation.reloadData()
  302. checkLoadingMoreVisible(segment: "all")
  303. }
  304. if (self.allTransaction.count>0){
  305. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  306. }
  307. case 1:
  308. self.segment = "received"
  309. ///To display list from first page only When tap to received segmentControl
  310. allPage = 0
  311. if receivedTransaction.count == 0{
  312. startLoading()
  313. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: receivedPage,size: allSize)
  314. }else{
  315. stopLoading()
  316. tableViewTranscation.reloadData()
  317. checkLoadingMoreVisible(segment: "received")
  318. }
  319. if (receivedTransaction.count > 0){
  320. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  321. }
  322. case 2:
  323. self.segment = "sent"
  324. ///To display list from first page only When tap to sent segmentControl
  325. allPage = 0
  326. if sentTransaction.count == 0{
  327. startLoading()
  328. tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: sentPage, size:allSize)
  329. }else{
  330. stopLoading()
  331. tableViewTranscation.reloadData()
  332. checkLoadingMoreVisible(segment: "sent")
  333. }
  334. if (sentTransaction.count > 0){
  335. self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
  336. }
  337. default:
  338. break
  339. }
  340. }
  341. // MARK: - Navigation
  342. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  343. if (segue.identifier == "searchTransaction") {
  344. if status == true {
  345. let vc = segue.destination as! TransactionSearchViewController
  346. vc.status = status
  347. } else {
  348. let vc = segue.destination as! TransactionSearchViewController
  349. vc.status = status
  350. }
  351. }
  352. }
  353. /**
  354. Transaction from is differ as per the type of payoutMode
  355. - Parameter payoutMode: the type of payout mode are like cash,bank,topup door to dorr and withdraw.
  356. - Parameter transferType: the type of transferType are like offer and request.
  357. - Parameter row: table view row
  358. */
  359. func setTransactionToName(payoutMode: String,transactionType: String,row:Int){
  360. switch segment {
  361. case "all":
  362. if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
  363. transactionCell?.labelName.text = transactionType + allTransaction[row].receiverPhone
  364. }else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
  365. transactionCell?.labelName.text = transactionType + allTransaction[row].bankName
  366. }
  367. else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
  368. transactionCell?.labelName.text = transactionType + firstWord(text: allTransaction[row].senderName)
  369. }
  370. else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
  371. transactionCell?.labelName.text = transactionType + allTransaction[row].bankName
  372. } else if (payoutMode.caseInsensitiveCompare("wallet transfer") == ComparisonResult.orderedSame) {
  373. if transactionType == "From: "{
  374. if let name = allTransaction[row].senderName{
  375. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  376. }
  377. } else {
  378. if let name = allTransaction[row].receiverName{
  379. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  380. }
  381. }
  382. } else {
  383. if let name = allTransaction[row].receiverName{
  384. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  385. }
  386. }
  387. case "received":
  388. if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
  389. transactionCell?.labelName.text = transactionType + receivedTransaction[row].receiverPhone
  390. }else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
  391. transactionCell?.labelName.text = transactionType + receivedTransaction[row].bankName
  392. }
  393. else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
  394. transactionCell?.labelName.text = transactionType + firstWord(text: receivedTransaction[row].senderName)
  395. }
  396. else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
  397. transactionCell?.labelName.text = transactionType + receivedTransaction[row].bankName
  398. }else if (payoutMode.caseInsensitiveCompare("wallet transfer") == ComparisonResult.orderedSame){
  399. if let name = receivedTransaction[row].senderName{
  400. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  401. }
  402. } else {
  403. if let name = receivedTransaction[row].receiverName{
  404. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  405. }
  406. }
  407. case "sent":
  408. if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
  409. transactionCell?.labelName.text = transactionType + sentTransaction[row].receiverPhone
  410. }else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
  411. transactionCell?.labelName.text = transactionType + sentTransaction[row].bankName
  412. }
  413. else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
  414. transactionCell?.labelName.text = transactionType + firstWord(text: sentTransaction[row].senderName)
  415. }
  416. else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
  417. transactionCell?.labelName.text = transactionType + sentTransaction[row].bankName
  418. }else {
  419. if let name = sentTransaction[row].receiverName{
  420. transactionCell?.labelName.text = transactionType + firstWord(text: name)
  421. }
  422. }
  423. default:
  424. break
  425. }
  426. }
  427. }
  428. extension TranscationStatementViewController: UITableViewDataSource, UITableViewDelegate {
  429. /**
  430. Return size of an array as per the segment selected
  431. */
  432. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  433. switch section {
  434. case 0:
  435. switch self.segment {
  436. case "all":
  437. return allTransaction.count
  438. case "received":
  439. return receivedTransaction.count
  440. case "sent":
  441. return sentTransaction.count
  442. default :
  443. return 0
  444. }
  445. default:
  446. return 1
  447. }
  448. }
  449. /**
  450. Two section, one is for transactions view and other for load more view
  451. */
  452. func numberOfSections(in tableView: UITableView) -> Int {
  453. return 2
  454. }
  455. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  456. switch indexPath.section {
  457. case 0:
  458. transactionCell = tableView.dequeueReusableCell(withIdentifier: "transactionStatementCell", for: indexPath) as? TranscationTableViewCell
  459. transactionCell?.layer.borderColor = UIColor(red:0.91, green:0.93, blue:0.95, alpha:1.0).cgColor
  460. transactionCell?.layer.borderWidth = 5
  461. transactionCell?.layer.cornerRadius = 10
  462. switch segment{
  463. case "all":
  464. if allTransaction[indexPath.row].transactionType == "received" {
  465. transactionCell?.labelAmountPay.textColor = UIColor(red:0.18, green:0.19, blue:0.57, alpha:1.0)
  466. if let payout = allTransaction[indexPath.row].payoutMethod{
  467. setTransactionToName(payoutMode: payout,transactionType: "From: ", row: indexPath.row)
  468. }
  469. if let amount = allTransaction[indexPath.row].payoutAmountOriginal{
  470. if amount == "N/A" {
  471. transactionCell?.labelAmountPay.text = amount
  472. } else {
  473. transactionCell?.labelAmountPay.text = "+" + getCommaAddedAmountString(amountString: amount)
  474. }
  475. }
  476. } else {
  477. transactionCell?.labelAmountPay.textColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  478. if let payout = allTransaction[indexPath.row].payoutMethod{
  479. setTransactionToName(payoutMode: payout,transactionType: "To: ", row: indexPath.row)
  480. }
  481. if let amount = allTransaction[indexPath.row].payoutAmountOriginal{
  482. if amount == "N/A" {
  483. transactionCell?.labelAmountPay.text = amount
  484. } else {
  485. transactionCell?.labelAmountPay.text = "-" + getCommaAddedAmountString(amountString: amount)
  486. }
  487. }
  488. }
  489. if let allDate = allTransaction[indexPath.row].date{
  490. transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: allDate)
  491. }
  492. if let payoutMethod = allTransaction[indexPath.row].payoutMethod{
  493. transactionCell?.labelPayment.text = payoutMethod
  494. }
  495. if let transactionId = allTransaction[indexPath.row].transactionId{
  496. transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
  497. }
  498. case "received":
  499. transactionCell?.labelAmountPay.textColor = UIColor(red:0.18, green:0.19, blue:0.57, alpha:1.0)
  500. if let payout = receivedTransaction[indexPath.row].payoutMethod{
  501. setTransactionToName(payoutMode: payout,transactionType: "From: ", row: indexPath.row)
  502. }
  503. if let amount = receivedTransaction[indexPath.row].payoutAmountOriginal{
  504. if amount == "N/A" {
  505. transactionCell?.labelAmountPay.text = amount
  506. } else {
  507. transactionCell?.labelAmountPay.text = "+" + getCommaAddedAmountString(amountString: amount)
  508. }
  509. }
  510. if let receivedDate = receivedTransaction[indexPath.row].date{
  511. transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: receivedDate)
  512. }
  513. if let payoutMethod = receivedTransaction[indexPath.row].payoutMethod{
  514. transactionCell?.labelPayment.text = payoutMethod
  515. }
  516. if let transactionId = receivedTransaction[indexPath.row].transactionId{
  517. transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
  518. }
  519. case "sent":
  520. transactionCell?.labelAmountPay.textColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
  521. if let payout = sentTransaction[indexPath.row].payoutMethod{
  522. setTransactionToName(payoutMode: payout,transactionType: "To: ", row: indexPath.row)
  523. }
  524. if let amount = sentTransaction[indexPath.row].payoutAmountOriginal{
  525. if amount == "N/A" {
  526. transactionCell?.labelAmountPay.text = amount
  527. } else {
  528. transactionCell?.labelAmountPay.text = "-" + getCommaAddedAmountString(amountString: amount)
  529. }
  530. }
  531. if let sentDate = sentTransaction[indexPath.row].date{
  532. transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: sentDate)
  533. }
  534. if let payoutMethod = sentTransaction[indexPath.row].payoutMethod{
  535. transactionCell?.labelPayment.text = payoutMethod
  536. }
  537. if let transactionId = sentTransaction[indexPath.row].transactionId{
  538. transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
  539. }
  540. default:
  541. break
  542. }
  543. return transactionCell!
  544. default :
  545. let loadMoreCell = tableView.dequeueReusableCell(withIdentifier: "loadMoreButtonCell", for: indexPath) as! TranscationTableViewCell
  546. loadMoreCell.loadMoreButtonOutlet.addTarget(self, action: #selector(loadMoreButtonAction(sender:)), for: .touchUpInside)
  547. self.loadMoreButtonOutlet = loadMoreCell.loadMoreButtonOutlet
  548. return loadMoreCell
  549. }
  550. }
  551. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  552. switch segmentedControl.selectedSegmentIndex {
  553. case 0:
  554. selectedTransaction = allTransaction[indexPath.row]
  555. case 1:
  556. selectedTransaction = receivedTransaction[indexPath.row]
  557. case 2:
  558. selectedTransaction = sentTransaction[indexPath.row]
  559. default:
  560. return
  561. }
  562. do {
  563. let encodedTransaction = try JSONEncoder().encode(selectedTransaction)
  564. let encodedTransactionDictionary = try JSONSerialization.jsonObject(with: encodedTransaction, options: .allowFragments) as? [String: Any]
  565. switch (encodedTransactionDictionary!["payoutMethod"] as? String)?.lowercased() {
  566. case "cash"?, "bank"?, "door to door"?:
  567. let storyboard = UIStoryboard.init(name: "RecipientListViewController", bundle: Bundle.main)
  568. let transferSuccessViewController = storyboard.instantiateViewController(withIdentifier: "showTransferInfo") as! TransferSuccessfulViewController
  569. transferSuccessViewController.responseDetails = encodedTransactionDictionary
  570. self.navigationController!.pushViewController(transferSuccessViewController, animated: true)
  571. case "wallet transfer"?:
  572. let storyboard = UIStoryboard.init(name: "WalletTransfer", bundle: Bundle.main)
  573. let walletSuccessViewController = storyboard.instantiateViewController(withIdentifier: "walletSuccess") as! WalletSuccessViewController
  574. walletSuccessViewController.transaction = selectedTransaction
  575. self.navigationController!.pushViewController(walletSuccessViewController, animated: true)
  576. case "load balance"?, "withdraw"?, "bonus"?, "topup"?:
  577. popUpMessageInfo(value: 16, title: "Alert", message: "No details available")
  578. default:
  579. popUpMessageInfo(value: 16, title: "Alert", message: "No details available")
  580. }
  581. } catch _ {
  582. }
  583. }
  584. }