Allow showing from amounts in overhead allocation

This commit is contained in:
Piv
2023-03-11 20:19:28 +10:30
parent 7cd893cbf8
commit f5bc441fdb
9 changed files with 246 additions and 62 deletions

View File

@@ -12,6 +12,7 @@
5A1986FB2996502C00FA0471 /* FileButtonSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */; };
5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A450750298CE6D500E3D402 /* CsvDocument.swift */; };
5A45075B298D01EF00E3D402 /* libcoster_rs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A45075A298D01EF00E3D402 /* libcoster_rs.a */; };
5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4995C729BC423900A1A107 /* TempFileDocument.swift */; };
5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */; };
5ADD9F2F298A713300F998F5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2E298A713300F998F5 /* ContentView.swift */; };
5ADD9F31298A713400F998F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5ADD9F30298A713400F998F5 /* Assets.xcassets */; };
@@ -48,6 +49,7 @@
5A450755298CFFE400E3D402 /* create-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "create-lib.sh"; sourceTree = "<group>"; };
5A450756298D00AE00E3D402 /* remove-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "remove-lib.sh"; sourceTree = "<group>"; };
5A45075A298D01EF00E3D402 /* libcoster_rs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcoster_rs.a; path = "../costerrs/target/aarch64-apple-ios/release/libcoster_rs.a"; sourceTree = "<group>"; };
5A4995C729BC423900A1A107 /* TempFileDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempFileDocument.swift; sourceTree = "<group>"; };
5ADD9F29298A713300F998F5 /* FastCoster.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FastCoster.app; sourceTree = BUILT_PRODUCTS_DIR; };
5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FastCosterApp.swift; sourceTree = "<group>"; };
5ADD9F2E298A713300F998F5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -140,6 +142,7 @@
5A1986F62996436500FA0471 /* OverheadAllocation.swift */,
5A1986F82996436D00FA0471 /* MoveMoney.swift */,
5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */,
5A4995C729BC423900A1A107 /* TempFileDocument.swift */,
);
path = FastCoster;
sourceTree = "<group>";
@@ -348,6 +351,7 @@
5A1986F92996436D00FA0471 /* MoveMoney.swift in Sources */,
5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */,
5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */,
5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */,
5A1986F72996436500FA0471 /* OverheadAllocation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -14,8 +14,11 @@ struct OverheadAllocation: View {
@State private var allocationStatistics: String?
@State private var costCentres: String?
@State private var showExportPicker = false
@State private var document: CsvDocument?
@State private var document: TempFileDocument?
@State private var accountType = "E"
@State private var show_from = false
private let tempPath = FileManager.default.temporaryDirectory.appendingPathComponent("OverheadAllocation.csv", conformingTo: .commaSeparatedText)
var body: some View {
VStack {
@@ -35,6 +38,9 @@ struct OverheadAllocation: View {
costCentres = result
}
TextField("Account Type", text: $accountType)
Toggle(isOn: $show_from) {
Text("Show from cc movements")
}
Button {
allocate_overheads()
} label: {
@@ -43,23 +49,28 @@ struct OverheadAllocation: View {
.fileExporter(isPresented: $showExportPicker, document: document, contentType: .commaSeparatedText) { result in
if case .success = result {
// TODO: Delete the temp file
do {
try FileManager.default.removeItem(at: tempPath)
} catch {
}
}else {
}
}
}
}.padding()
.textFieldStyle(.roundedBorder)
}
func allocate_overheads() {
DispatchQueue.global(qos: .userInitiated).async {
// Run move money
let result = allocate_overheads_from_text(lines, accounts, allocationStatistics, areas, costCentres, accountType, false);
let finalDocument = TempFileDocument(url: tempPath)
allocate_overheads_from_text_to_file(lines, accounts, allocationStatistics, areas, costCentres, accountType, tempPath.absoluteString, false, show_from)
DispatchQueue.main.async {
document = CsvDocument(data: String(cString: result!))
allocate_overheads_from_text_free(result)
document = finalDocument
showExportPicker = true;
}
}

View File

@@ -0,0 +1,32 @@
//
// TempFileDocument.swift
// FastCoster
//
// Created by Michael Pivato on 11/3/2023.
//
import Foundation
import SwiftUI
import UniformTypeIdentifiers
struct TempFileDocument: FileDocument {
var tempFileUrl: URL?
var wrapper: FileWrapper?
static var readableContentTypes: [UTType] {[.commaSeparatedText]}
init(configuration: ReadConfiguration) throws {
wrapper = configuration.file
}
init(url: URL) {
tempFileUrl = url
}
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
return try wrapper ?? FileWrapper(url: tempFileUrl!)
}
}