`struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(sortDescriptors: [
SortDescriptor(\.date)
]) var taxes: FetchedResults<Tax>
@State private var showingAddScreen = false
// @EnvironmentObject var vm = ViewModel()
@State var PDFUrls: URL?
@State var showSheet: Bool = false
@State private var selectedName: String?
@State private var expanded: Bool = false
let tax: Tax
// @State private var items: [Any] = []
// @State private var sheet: Bool = false
// let columns = [GridItem(.fixed(50)), GridItem(.fixed(50)), GridItem(.fixed(50)), GridItem(.fixed(50)), GridItem(.fixed(50))]
var body: some View {
// NavigationView {
// VStack {
VStack {
HStack {
// padding()
EditButton()
// .background(Color.yellow)
.padding(.leading, 20)
Spacer()
Button {
exportPDF {
self
} completion: { status, url in
if let url = url, status {
self.PDFUrls = url
self.showSheet.toggle()
}
else {
print("Failed to produce PDF")
}
}
} label: {
Image(systemName: "square.and.arrow.up")
//.background(Color.yellow)
.padding(.trailing, 15)
// .font(.title2)
// .foregroundColor(Color.black.opacity(0.7))
}
//Spacer()
Button {
showingAddScreen.toggle()
} label: {
// Label("Add Book", systemImage: "plus")
Image(systemName: "plus")
.padding(.trailing, 20)
// .background(Color.yellow)
}
// padding()
}
HStack {
Text("Tax Deduction Register")
.padding(.top, 10)
.padding(.bottom, 10)
.multilineTextAlignment(.leading)
// .frame(width: 150)
.font(.system(size: 25, weight: .heavy, design: .monospaced))
.font(.largeTitle)
//.background(Color.yellow)
}
}
// ScrollView(.horizontal) {
// List {
// LazyVGrid(columns: columns) {
HStack {
Text("Date")
.frame(width: 25)
.padding(.leading, 15)
.padding()
.font(.system(size: 10, weight: .heavy, design: .rounded))
.font(.largeTitle)
// .background(Color.blue)
Text("Description")
.padding()
.frame(width: 95)
.font(.system(size: 10, weight: .heavy, design: .rounded))
.font(.largeTitle)
// .background(Color.blue)
Text("Category")
.padding()
.frame(width: 85)
.font(.system(size: 10, weight: .heavy, design: .rounded))
.font(.largeTitle)
// .background(Color.blue)
Text("Payment")
.padding()
.frame(width: 80)
.font(.system(size: 10, weight: .heavy, design: .rounded))
.font(.largeTitle)
//.background(Color.blue)
Text("GST")
.frame(width: 25)
.padding()
.font(.system(size: 10, weight: .heavy, design: .rounded))
.font(.largeTitle)
// .background(Color.blue)
// Text(" ")
// }
}
// LazyVGrid(columns: columns) {
List {
ForEach(taxes) { tax in
HStack {
Text(tax.date ?? "No Date")
// .background(Color.red)
.padding(.trailing, 5)
// .padding()
.frame(width: 45)
.font(.system(size: 7.5, weight: .medium, design: .serif))
.font(.title2)
Text(tax.about ?? "No Description")
// .background(Color.red)
// .padding()
.frame(width: 95)
.font(.system(size: 7.5, weight: .medium, design: .serif))
.font(.title2)
Text(tax.category ?? "Fantasy")
// .background(Color.red)
// .padding()
.frame(width: 55)
.font(.system(size: 7.5, weight: .medium, design: .serif))
.font(.title2)
let cost = tax.cost
let theCost = Double(cost!) ?? 0
let actualCost = Double(theCost)
let theGST = theCost / 10
let actualGST = Double(theGST)
Text("$\(actualCost, specifier: "%.2f")")
// .padding()
// .background(Color.red)
.frame(width: 90)
.font(.system(size: 7.5, weight: .medium, design: .serif))
.font(.title2)
Text("$\(actualGST, specifier: "%.2f")")
// .padding()
// .background(Color.red)
.frame(width: 55)
.font(.system(size: 7.5, weight: .medium, design: .serif))
.font(.title2)
// Text(" ")
}
}
.onDelete(perform: deleteBooks)
}
// .onDelete(perform: deleteBooks)
// .onMove(perform: moveTask)
// .listRowSeparatorTint(.gray)
// .listRowSeparator(.hidden)
// }
.listStyle(.plain)
// .navigationTitle("Tax Deduction Register")
// .toolbar {
// ToolbarItem(placement: .navigationBarLeading) {
// EditButton()
// }
//
// ToolbarItem(placement: .navigationBarTrailing) {
// Button {
// showingAddScreen.toggle()
// } label: {
// Label("Add Book", systemImage: "plus")
// }
// }
// }
.sheet(isPresented: $showingAddScreen) {
AddTaxView()
}
.sheet(isPresented: $showSheet) {
PDFUrls = nil
} content: {
if let PDFUrl = PDFUrls {
ShareSheet(urls: [PDFUrl])
}
}
// Button {
// exportPDF {
// self
// } completion: { status, url in
// if let url = url, status {
// self.PDFUrls = url
// self.showSheet.toggle()
// }
// else {
// print("Failed to produce PDF")
// }
// }
//
// } label: {
// Image(systemName: "square.and.arrow.up")
// //.background(Color.yellow)
// .padding(.trailing, 15)
// // .font(.title2)
// // .foregroundColor(Color.black.opacity(0.7))
//
// }
// .sheet(isPresented: $sheet) {
// ShareSheet(items: items)
// }
// }
// }
}
// }
func deleteBooks(at offsets: IndexSet) {
for offset in offsets {
let tax = taxes[offset]
moc.delete(tax)
}
try?moc.save()
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(tax: Tax())
}
}
}
Post
Replies
Boosts
Views
Activity
I am on Mac IOS using swift