Started searching for Remittees

This commit is contained in:
dankito 2020-08-06 02:13:47 +02:00
parent 878f51ac31
commit d061e7f81c
4 changed files with 82 additions and 0 deletions

View File

@ -89,6 +89,30 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher {
return UserDefaults.standard.data(forKey: filePath)
}
func findRemittees(query: String) -> [Remittee] {
var transactions: [PersistedAccountTransaction] = []
do {
let request: NSFetchRequest<PersistedAccountTransaction> = PersistedAccountTransaction.fetchRequest()
request.returnsObjectsAsFaults = false
request.predicate = NSPredicate(format: "otherPartyName CONTAINS[c] %@", query)
request.propertiesToFetch = [ "otherPartyName", "otherPartyBankCode", "otherPartyAccountId" ]
request.sortDescriptors = [ NSSortDescriptor(key: "otherPartyName", ascending: true) ]
try transactions = context.fetch(request)
} catch {
NSLog("Could not request Customers: \(error)")
}
let remittees = transactions.map( { Remittee(name: $0.otherPartyName ?? "", iban: $0.otherPartyAccountId, bic: $0.otherPartyBankCode, bankName: nil) } )
let uniqueRemittees = Set<Remittee>(remittees)
return Array(uniqueRemittees)
}
func deleteAll() {
do {

View File

@ -46,6 +46,13 @@ extension BankInfo : Identifiable {
}
extension Remittee : Identifiable {
public var id: String { name.localizedLowercase + "_" + (iban ?? "") }
}
extension TanProcedure : Identifiable {
public var id: String { self.bankInternalProcedureCode }

View File

@ -0,0 +1,46 @@
import SwiftUI
import BankingUiSwift
struct RemitteeListItem: View {
let remittee: Remittee
var body: some View {
VStack {
HStack {
Text(remittee.name)
.font(.headline)
Spacer()
}
HStack {
Text(remittee.bankName ?? "")
Spacer()
}
.padding(.vertical, 6)
HStack {
Text(remittee.iban ?? "")
Text(remittee.bic ?? "")
Spacer()
}
.padding(.bottom, 6.0)
}
}
}
struct RemitteeListItem_Previews: PreviewProvider {
static var previews: some View {
RemitteeListItem(remittee: Remittee(name: "Marieke Musterfrau", iban: "DE12876543211234567890", bic: "ABZODEBBXX", bankName: "Abzockbank Berlin"))
}
}

View File

@ -17,6 +17,9 @@ struct TransferMoneyDialog: View {
@State private var remitteeName: String = ""
@State private var isValidRemitteeNameEntered = false
@State private var showRemitteeAutocompleteList = false
@State private var remitteeSearchResults = [Remittee]()
@State private var remitteeIban: String = ""
@State private var isValidRemitteeIbanEntered = false
@ -49,6 +52,8 @@ struct TransferMoneyDialog: View {
@Inject private var presenter: BankingPresenterSwift
@Inject private var persistence: CoreDataBankingPersistence
init() {
self.accountsSupportingTransferringMoney = self.presenter.bankAccounts.filter({ $0.supportsTransferringMoney })