// // Pointage.swift // // // /* It is not possible to compile if the line 146 de this file is not in commentary. Otherwise we get this alarm : The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions */ import SwiftUI struct PointageView: View { let listMois: [String] = [" .... ", "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Décembre"] let choixOuiNon: [String] = ["...", "Non", "Oui"] private let largCol: [CGFloat] = [40, 70, 70, 400, 80, 80, 70] private let hautLig: CGFloat = 20 private var readDataBase: ReadRelevesBancaires = ReadRelevesBancaires() @AppStorage("Annee", store: .standard) var annee: String = "" @State var fetchRecords: [ReleveBancaire] = [] @State var iMx: Int = 0 @State var moisSel: String = "" @State var ipx: Int = 0 @State var pointSel: String = "" var body: some View { VStack (alignment: HorizontalAlignment.leading) { HStack { // Button de relance du filtrage Spacer(minLength: 50) Button (action: { fetchRecords = readDataBase.fetchRecords(annee: annee, mois: moisSel, pointe: pointSel) ipx = 0 iMx = 0 }) { Text ("Filtrer") } // Affichage de l'année en cours (voir préférence) Text(annee) .frame(width: 40, height: 25, alignment: .center) .foregroundColor(Color.red) // Choix du mois .padding(.leading, 15) Picker("", selection: $iMx) { ForEach (0.. [ReleveBancaire] { var fetchRecords: [ReleveBancaire] = [] var anneePredicat: NSPredicate = NSPredicate() var moisPredicat: NSPredicate = NSPredicate() var poinPredicat: NSPredicate = NSPredicate() anneePredicat = NSPredicate(format: "date CONTAINS %@", annee) if mois != "" { let moisLoc = "/" + mois + "/" moisPredicat = NSPredicate(format: "date CONTAINS %@", moisLoc) } if pointe != "" { let pointeLoc = pointe poinPredicat = NSPredicate (format: "pointage LIKE %@", pointeLoc) } let compoundPrediccat: NSCompoundPredicate = NSCompoundPredicate( andPredicateWithSubpredicates: [ anneePredicat, moisPredicat]) // Create a fetch request for a specific Entity type let fetchRequest: NSFetchRequest fetchRequest = ReleveBancaire.fetchRequest() if mois != "" && pointe != "" { fetchRequest.predicate = compoundPrediccat } fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] //fetchRequest.fetchLimit = 1 // Fetch records from ReleveBancaire do { fetchRecords = try context.fetch(fetchRequest) } catch let error as NSError { print("Erreur interrogation base : \(error) ") } return fetchRecords } // Enregistrement du pointage func updateRecord (record: ReleveBancaire) { do { try context.save() } catch let error as NSError { print("Erreur update base : \(error) ") } } }