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
668 lines
30 KiB
//
|
|
// TranscationStatementViewController.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by FMI-12 on 2/6/18.
|
|
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
import UIKit
|
|
|
|
class TranscationStatementViewController: UIViewController,TableViewCellTransactionDelegate {
|
|
|
|
@IBOutlet weak var tableViewTranscation: UITableView!
|
|
@IBOutlet weak var segmentedControl: UISegmentedControl!
|
|
|
|
private var selectedTransaction: Transaction?
|
|
private var tracktransactionviewmodel = TrackTransactionViewModel()
|
|
private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
|
|
|
|
private var transactionCell: TranscationTableViewCell?
|
|
private var loadMoreButtonOutlet:UIButton?
|
|
private var status: Bool?
|
|
|
|
private var segment: String = "all"
|
|
private var allSize: Int = 20
|
|
private var allPage: Int = 0
|
|
private var receivedPage: Int = 0
|
|
private var sentPage: Int = 0
|
|
private var allTransaction = [Transaction]()
|
|
private var sentTransaction = [Transaction]()
|
|
private var receivedTransaction = [Transaction]()
|
|
public var fromNotification: Int?
|
|
|
|
public static var notificationCode: String = ""
|
|
let pNotificationArray = ["p200","p203","p206","p207","p204", "p208"]
|
|
|
|
public static var transactionConnectionTimeOutCheck = 0
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
setUpAnotherLoginListener(genericviewmodel: tracktransactionviewmodel)
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
if pNotificationArray.contains(TranscationStatementViewController.notificationCode) {
|
|
setUpNavBar(id: 207, title: "Transaction Statement")
|
|
}else {
|
|
setUpNavBar(id: 201, title: "Transaction Statement")
|
|
}
|
|
|
|
selectedSegmentControlTab()
|
|
TranscationStatementViewController.notificationCode.removeAll()
|
|
|
|
self.tableViewTranscation.delegate = self
|
|
self.tableViewTranscation.dataSource = self
|
|
self.tableViewTranscation.estimatedRowHeight = 119
|
|
self.tableViewTranscation.rowHeight = UITableViewAutomaticDimension
|
|
self.tableViewTranscation.tableFooterView = UIView()
|
|
|
|
segmentedControl.addTarget(self, action: #selector(transactionTypeChanged(_:)), for: .valueChanged)
|
|
|
|
|
|
tracktransactionviewmodel.transactionListConnectionTimeOut.value = nil
|
|
/**
|
|
connection timeout
|
|
*/
|
|
tracktransactionviewmodel.transactionListConnectionTimeOut.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
if self.fromNotification != 0{
|
|
if TranscationStatementViewController.transactionConnectionTimeOutCheck == 0{
|
|
TranscationStatementViewController.transactionConnectionTimeOutCheck = TranscationStatementViewController.transactionConnectionTimeOutCheck+1
|
|
self.popUpMessage(value: 30)
|
|
}
|
|
}
|
|
|
|
self.clearAllArray()
|
|
self.tableViewTranscation.reloadData()
|
|
self.loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
|
|
/**
|
|
Check internet connection
|
|
*/
|
|
tracktransactionviewmodel.internetConnection.value = nil
|
|
tracktransactionviewmodel.internetConnection.bind { [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
self.popUpMessage(value: 15)
|
|
self.clearAllArray()
|
|
self.tableViewTranscation.reloadData()
|
|
self.loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
|
|
/**
|
|
Request user all transactions
|
|
*/
|
|
self.startLoading()
|
|
|
|
tracktransactionviewmodel.transactionListObtained.bind{ [unowned self] in
|
|
guard $0 != nil else {
|
|
return
|
|
}
|
|
|
|
guard $0! else {
|
|
self.stopLoading()
|
|
if TranscationStatementViewController.transactionConnectionTimeOutCheck == 0{
|
|
TranscationStatementViewController.transactionConnectionTimeOutCheck = TranscationStatementViewController.transactionConnectionTimeOutCheck+1
|
|
self.popUpMessageError(value: 10, message: self.tracktransactionviewmodel.getErrorMessage())
|
|
}
|
|
return
|
|
}
|
|
self.stopLoading()
|
|
if self.tracktransactionviewmodel.getCount() > 0{
|
|
self.loadTableView()
|
|
}else{
|
|
|
|
self.loadTableView()
|
|
}
|
|
}
|
|
|
|
switch segmentedControl.selectedSegmentIndex {
|
|
|
|
case 1:
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
|
|
case 2:
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
|
|
default:
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
|
|
}
|
|
|
|
}
|
|
|
|
@IBAction func actionSearch(_ sender: Any) {
|
|
status = true
|
|
self.performSegue(withIdentifier: "searchTransaction", sender: nil)
|
|
}
|
|
|
|
@IBAction func actionCalendarView(_ sender: Any) {
|
|
status = false
|
|
self.performSegue(withIdentifier: "searchTransaction", sender: nil)
|
|
}
|
|
|
|
/**
|
|
Remove all array
|
|
*/
|
|
func clearAllArray(){
|
|
allTransaction.removeAll()
|
|
sentTransaction.removeAll()
|
|
receivedTransaction.removeAll()
|
|
}
|
|
|
|
/**
|
|
Redirect to segment as per the notification type
|
|
*/
|
|
func selectedSegmentControlTab(){
|
|
switch TranscationStatementViewController.notificationCode {
|
|
case "204", "208","p204", "p208":
|
|
segment = "received"
|
|
segmentedControl.selectedSegmentIndex = 1
|
|
|
|
case "200","203","206","207","p200","p203","p206","p207":
|
|
segment = "sent"
|
|
segmentedControl.selectedSegmentIndex = 2
|
|
default:
|
|
segment = "all"
|
|
segmentedControl.selectedSegmentIndex = 0
|
|
}
|
|
}
|
|
|
|
/**
|
|
Append more transactions data into global array and reload tableview
|
|
*/
|
|
func loadTableView(){
|
|
self.tableViewTranscation.isHidden = false
|
|
switch self.segment {
|
|
case "all":
|
|
allTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
|
|
if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
|
|
self.loadMoreButtonOutlet?.isHidden = false
|
|
}else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
|
|
self.loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
case "received":
|
|
receivedTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
|
|
if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
|
|
self.loadMoreButtonOutlet?.isHidden = false
|
|
}else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
|
|
self.loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
case "sent":
|
|
sentTransaction.append(contentsOf:self.tracktransactionviewmodel.getTransactions())
|
|
if self.tracktransactionviewmodel.getTransactions().count == self.allSize{
|
|
self.loadMoreButtonOutlet?.isHidden = false
|
|
}else if (self.tracktransactionviewmodel.getTransactions().count < self.allSize || self.tracktransactionviewmodel.getTransactions().count == 0){
|
|
self.loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
self.tableViewTranscation.reloadData()
|
|
self.tableViewStartFromBeginningRow()
|
|
}
|
|
|
|
/**
|
|
Show tableview from 0 index
|
|
*/
|
|
func tableViewStartFromBeginningRow(){
|
|
switch segment {
|
|
case "all":
|
|
if (allTransaction.count > 0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
case "received":
|
|
if (receivedTransaction.count>0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
case "sent":
|
|
if (sentTransaction.count>0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
/**
|
|
Request when user wants to view old transactions
|
|
*/
|
|
@objc func loadMoreButtonAction(sender: TranscationTableViewCell) {
|
|
|
|
self.startLoading()
|
|
|
|
switch segment {
|
|
case "all":
|
|
self.allPage = self.allPage+1
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil,page: self.allPage, size: self.allSize)
|
|
case "received":
|
|
self.receivedPage = self.receivedPage+1
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: self.receivedPage, size: self.allSize)
|
|
case "sent":
|
|
self.sentPage = self.sentPage+1
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: self.sentPage, size: self.allSize)
|
|
default :
|
|
break
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
Check whether transaction type is sent or received
|
|
|
|
- Parameter payoutMode: the type of payout mode are like cash,bank,topup door to dorr and withdraw.
|
|
- Parameter transferType: the type of transferType are like offer and request.
|
|
- Returns : transactions type is sent or received
|
|
*/
|
|
// func checkSentOrReceive(payoutMode: String, userId: String?) -> String {
|
|
// if(payoutMode.caseInsensitiveCompare("cash") == ComparisonResult.orderedSame ||
|
|
// payoutMode.caseInsensitiveCompare("bank") == ComparisonResult.orderedSame ||
|
|
// payoutMode.caseInsensitiveCompare("topup") == ComparisonResult.orderedSame ||
|
|
// payoutMode.caseInsensitiveCompare("Door to Door") == ComparisonResult.orderedSame ||
|
|
// payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
|
|
// return "sent"
|
|
// }else if (payoutMode.caseInsensitiveCompare("wallet Transfer") == ComparisonResult.orderedSame){
|
|
// let selfUserId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
|
|
//
|
|
// if userId != nil {
|
|
// if userId == selfUserId! {
|
|
// return "sent"
|
|
// }
|
|
// return "received"
|
|
// }
|
|
// }
|
|
// return "received"
|
|
// }
|
|
|
|
/**
|
|
Disable user interaction while fetching data from api
|
|
*/
|
|
func startLoading(){
|
|
tableViewTranscation.isHidden = true
|
|
disableUserInteractions()
|
|
showActivityIndicator(activityIndicator: activityIndicator)
|
|
}
|
|
|
|
/**
|
|
Enable user interaction while fetching data from api
|
|
*/
|
|
func stopLoading(){
|
|
tableViewTranscation.isHidden = false
|
|
enableUserInteractions()
|
|
dismissActivityIndicator(activityIndicator: activityIndicator)
|
|
}
|
|
|
|
/**
|
|
Show load more button if only transaction count value is greater than 20
|
|
|
|
- Parameter segment: UI have three different segment i.e. All, Received and Sent
|
|
*/
|
|
func checkLoadingMoreVisible(segment: String){
|
|
switch segment {
|
|
case "all":
|
|
if allTransaction.count >= self.allSize{
|
|
loadMoreButtonOutlet?.isHidden = false
|
|
}else{
|
|
loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
case "received":
|
|
if receivedTransaction.count >= self.allSize{
|
|
loadMoreButtonOutlet?.isHidden = false
|
|
}else{
|
|
loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
case "sent":
|
|
if sentTransaction.count >= self.allSize{
|
|
loadMoreButtonOutlet?.isHidden = false
|
|
}else{
|
|
loadMoreButtonOutlet?.isHidden = true
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
/**
|
|
Action handle when user switch between three different segment i.e. All , Received and Sent
|
|
*/
|
|
@objc func transactionTypeChanged(_ segControl: UISegmentedControl) {
|
|
switch segControl.selectedSegmentIndex {
|
|
|
|
case 0:
|
|
self.segment = "all"
|
|
///To display list from first page only When tap to all segmentControl
|
|
allPage = 0
|
|
|
|
if allTransaction.count == 0 {
|
|
startLoading()
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "", startDate: nil, endDate: nil, page: allPage, size: allSize)
|
|
}else{
|
|
stopLoading()
|
|
tableViewTranscation.reloadData()
|
|
checkLoadingMoreVisible(segment: "all")
|
|
}
|
|
if (self.allTransaction.count>0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
case 1:
|
|
self.segment = "received"
|
|
///To display list from first page only When tap to received segmentControl
|
|
allPage = 0
|
|
|
|
if receivedTransaction.count == 0{
|
|
startLoading()
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "received", startDate: nil, endDate: nil,page: receivedPage,size: allSize)
|
|
}else{
|
|
stopLoading()
|
|
tableViewTranscation.reloadData()
|
|
checkLoadingMoreVisible(segment: "received")
|
|
}
|
|
if (receivedTransaction.count > 0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
case 2:
|
|
self.segment = "sent"
|
|
///To display list from first page only When tap to sent segmentControl
|
|
allPage = 0
|
|
|
|
if sentTransaction.count == 0{
|
|
startLoading()
|
|
tracktransactionviewmodel.fetchTransactionList(recipientId: "", recipientName: "", transactionType: "sent", startDate: nil, endDate: nil,page: sentPage, size:allSize)
|
|
}else{
|
|
stopLoading()
|
|
tableViewTranscation.reloadData()
|
|
checkLoadingMoreVisible(segment: "sent")
|
|
}
|
|
if (sentTransaction.count > 0){
|
|
self.tableViewTranscation.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Navigation
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
if (segue.identifier == "searchTransaction") {
|
|
if status == true {
|
|
let vc = segue.destination as! TransactionSearchViewController
|
|
vc.status = status
|
|
} else {
|
|
let vc = segue.destination as! TransactionSearchViewController
|
|
vc.status = status
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
Transaction from is differ as per the type of payoutMode
|
|
|
|
- Parameter payoutMode: the type of payout mode are like cash,bank,topup door to dorr and withdraw.
|
|
- Parameter transferType: the type of transferType are like offer and request.
|
|
- Parameter row: table view row
|
|
*/
|
|
func setTransactionToName(payoutMode: String,transactionType: String,row:Int){
|
|
switch segment {
|
|
case "all":
|
|
if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + allTransaction[row].receiverPhone
|
|
}else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + allTransaction[row].bankName
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: allTransaction[row].senderName)
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + allTransaction[row].bankName
|
|
} else if (payoutMode.caseInsensitiveCompare("wallet transfer") == ComparisonResult.orderedSame) {
|
|
if transactionType == "From: "{
|
|
if let name = allTransaction[row].senderName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
} else {
|
|
if let name = allTransaction[row].receiverName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
}
|
|
} else {
|
|
if let name = allTransaction[row].receiverName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
}
|
|
case "received":
|
|
if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + receivedTransaction[row].receiverPhone
|
|
}else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + receivedTransaction[row].bankName
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: receivedTransaction[row].senderName)
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + receivedTransaction[row].bankName
|
|
}else if (payoutMode.caseInsensitiveCompare("wallet transfer") == ComparisonResult.orderedSame){
|
|
if let name = receivedTransaction[row].senderName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
} else {
|
|
if let name = receivedTransaction[row].receiverName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
}
|
|
case "sent":
|
|
if (payoutMode.caseInsensitiveCompare("Topup") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + sentTransaction[row].receiverPhone
|
|
}else if (payoutMode.caseInsensitiveCompare("withdraw") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + sentTransaction[row].bankName
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("bonus") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: sentTransaction[row].senderName)
|
|
}
|
|
else if (payoutMode.caseInsensitiveCompare("load balance") == ComparisonResult.orderedSame){
|
|
transactionCell?.labelName.text = transactionType + sentTransaction[row].bankName
|
|
}else {
|
|
if let name = sentTransaction[row].receiverName{
|
|
transactionCell?.labelName.text = transactionType + firstWord(text: name)
|
|
}
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
extension TranscationStatementViewController: UITableViewDataSource, UITableViewDelegate {
|
|
|
|
/**
|
|
Return size of an array as per the segment selected
|
|
*/
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
switch section {
|
|
case 0:
|
|
switch self.segment {
|
|
case "all":
|
|
return allTransaction.count
|
|
case "received":
|
|
return receivedTransaction.count
|
|
case "sent":
|
|
return sentTransaction.count
|
|
default :
|
|
return 0
|
|
}
|
|
default:
|
|
return 1
|
|
}
|
|
}
|
|
|
|
/**
|
|
Two section, one is for transactions view and other for load more view
|
|
*/
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
return 2
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
switch indexPath.section {
|
|
case 0:
|
|
|
|
transactionCell = tableView.dequeueReusableCell(withIdentifier: "transactionStatementCell", for: indexPath) as? TranscationTableViewCell
|
|
transactionCell?.layer.borderColor = UIColor(red:0.91, green:0.93, blue:0.95, alpha:1.0).cgColor
|
|
transactionCell?.layer.borderWidth = 5
|
|
transactionCell?.layer.cornerRadius = 10
|
|
|
|
switch segment{
|
|
case "all":
|
|
|
|
if allTransaction[indexPath.row].transactionType == "received" {
|
|
transactionCell?.labelAmountPay.textColor = UIColor(red:0.18, green:0.19, blue:0.57, alpha:1.0)
|
|
if let payout = allTransaction[indexPath.row].payoutMethod{
|
|
setTransactionToName(payoutMode: payout,transactionType: "From: ", row: indexPath.row)
|
|
}
|
|
if let amount = allTransaction[indexPath.row].payoutAmountOriginal{
|
|
if amount == "N/A" {
|
|
transactionCell?.labelAmountPay.text = amount
|
|
} else {
|
|
transactionCell?.labelAmountPay.text = "+" + getCommaAddedAmountString(amountString: amount)
|
|
}
|
|
}
|
|
} else {
|
|
transactionCell?.labelAmountPay.textColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
|
|
if let payout = allTransaction[indexPath.row].payoutMethod{
|
|
setTransactionToName(payoutMode: payout,transactionType: "To: ", row: indexPath.row)
|
|
}
|
|
if let amount = allTransaction[indexPath.row].payoutAmountOriginal{
|
|
if amount == "N/A" {
|
|
transactionCell?.labelAmountPay.text = amount
|
|
} else {
|
|
transactionCell?.labelAmountPay.text = "-" + getCommaAddedAmountString(amountString: amount)
|
|
}
|
|
}
|
|
}
|
|
if let allDate = allTransaction[indexPath.row].date{
|
|
transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: allDate)
|
|
}
|
|
if let payoutMethod = allTransaction[indexPath.row].payoutMethod{
|
|
transactionCell?.labelPayment.text = payoutMethod
|
|
}
|
|
if let transactionId = allTransaction[indexPath.row].transactionId{
|
|
transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
|
|
}
|
|
|
|
case "received":
|
|
|
|
transactionCell?.labelAmountPay.textColor = UIColor(red:0.18, green:0.19, blue:0.57, alpha:1.0)
|
|
if let payout = receivedTransaction[indexPath.row].payoutMethod{
|
|
setTransactionToName(payoutMode: payout,transactionType: "From: ", row: indexPath.row)
|
|
}
|
|
if let amount = receivedTransaction[indexPath.row].payoutAmountOriginal{
|
|
if amount == "N/A" {
|
|
transactionCell?.labelAmountPay.text = amount
|
|
} else {
|
|
transactionCell?.labelAmountPay.text = "+" + getCommaAddedAmountString(amountString: amount)
|
|
}
|
|
}
|
|
if let receivedDate = receivedTransaction[indexPath.row].date{
|
|
transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: receivedDate)
|
|
}
|
|
if let payoutMethod = receivedTransaction[indexPath.row].payoutMethod{
|
|
transactionCell?.labelPayment.text = payoutMethod
|
|
}
|
|
if let transactionId = receivedTransaction[indexPath.row].transactionId{
|
|
transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
|
|
}
|
|
|
|
case "sent":
|
|
transactionCell?.labelAmountPay.textColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)
|
|
if let payout = sentTransaction[indexPath.row].payoutMethod{
|
|
setTransactionToName(payoutMode: payout,transactionType: "To: ", row: indexPath.row)
|
|
}
|
|
if let amount = sentTransaction[indexPath.row].payoutAmountOriginal{
|
|
if amount == "N/A" {
|
|
transactionCell?.labelAmountPay.text = amount
|
|
} else {
|
|
transactionCell?.labelAmountPay.text = "-" + getCommaAddedAmountString(amountString: amount)
|
|
}
|
|
}
|
|
if let sentDate = sentTransaction[indexPath.row].date{
|
|
transactionCell?.labelDate.text = unixTimeStampToDate(unixTimeStamp: sentDate)
|
|
}
|
|
if let payoutMethod = sentTransaction[indexPath.row].payoutMethod{
|
|
transactionCell?.labelPayment.text = payoutMethod
|
|
}
|
|
if let transactionId = sentTransaction[indexPath.row].transactionId{
|
|
transactionCell?.labelTranscationNo.text = "Transaction No." + " " + transactionId
|
|
}
|
|
|
|
default:
|
|
break
|
|
}
|
|
|
|
return transactionCell!
|
|
|
|
default :
|
|
let loadMoreCell = tableView.dequeueReusableCell(withIdentifier: "loadMoreButtonCell", for: indexPath) as! TranscationTableViewCell
|
|
loadMoreCell.loadMoreButtonOutlet.addTarget(self, action: #selector(loadMoreButtonAction(sender:)), for: .touchUpInside)
|
|
|
|
self.loadMoreButtonOutlet = loadMoreCell.loadMoreButtonOutlet
|
|
return loadMoreCell
|
|
}
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
switch segmentedControl.selectedSegmentIndex {
|
|
case 0:
|
|
selectedTransaction = allTransaction[indexPath.row]
|
|
case 1:
|
|
selectedTransaction = receivedTransaction[indexPath.row]
|
|
case 2:
|
|
selectedTransaction = sentTransaction[indexPath.row]
|
|
default:
|
|
return
|
|
}
|
|
|
|
do {
|
|
let encodedTransaction = try JSONEncoder().encode(selectedTransaction)
|
|
|
|
let encodedTransactionDictionary = try JSONSerialization.jsonObject(with: encodedTransaction, options: .allowFragments) as? [String: Any]
|
|
|
|
switch (encodedTransactionDictionary!["payoutMethod"] as? String)?.lowercased() {
|
|
|
|
case "cash"?, "bank"?, "door to door"?:
|
|
let storyboard = UIStoryboard.init(name: "RecipientListViewController", bundle: Bundle.main)
|
|
let transferSuccessViewController = storyboard.instantiateViewController(withIdentifier: "showTransferInfo") as! TransferSuccessfulViewController
|
|
|
|
transferSuccessViewController.responseDetails = encodedTransactionDictionary
|
|
|
|
self.navigationController!.pushViewController(transferSuccessViewController, animated: true)
|
|
|
|
case "wallet transfer"?:
|
|
let storyboard = UIStoryboard.init(name: "WalletTransfer", bundle: Bundle.main)
|
|
let walletSuccessViewController = storyboard.instantiateViewController(withIdentifier: "walletSuccess") as! WalletSuccessViewController
|
|
|
|
walletSuccessViewController.transaction = selectedTransaction
|
|
|
|
self.navigationController!.pushViewController(walletSuccessViewController, animated: true)
|
|
|
|
|
|
case "load balance"?, "withdraw"?, "bonus"?, "topup"?:
|
|
popUpMessageInfo(value: 16, title: "Alert", message: "No details available")
|
|
|
|
default:
|
|
popUpMessageInfo(value: 16, title: "Alert", message: "No details available")
|
|
}
|
|
|
|
|
|
} catch _ {
|
|
|
|
}
|
|
}
|
|
}
|