131 lines
4.6 KiB
Swift
131 lines
4.6 KiB
Swift
import Dependencies
|
|
import Elementary
|
|
import ElementaryHTMX
|
|
import SharedModels
|
|
|
|
struct PurchaseOrderForm: HTML {
|
|
|
|
@Dependency(\.dateFormatter) var dateFormatter
|
|
|
|
let purchaseOrder: PurchaseOrder?
|
|
let shouldShow: Bool
|
|
|
|
init(purchaseOrder: PurchaseOrder? = nil, shouldShow: Bool = false) {
|
|
self.purchaseOrder = purchaseOrder
|
|
self.shouldShow = shouldShow
|
|
}
|
|
|
|
var content: some HTML {
|
|
Float(shouldDisplay: shouldShow, resetURL: .purchaseOrder(.index)) {
|
|
if shouldShow {
|
|
if purchaseOrder != nil {
|
|
p {
|
|
span(.class("label"), .style("margin-right: 15px;")) { "Note:" }
|
|
span { i(.style("font-size: 1em;")) {
|
|
"Vendor and Employee can not be changed once a purchase order has been created."
|
|
} }
|
|
}
|
|
}
|
|
form(
|
|
.hx.post(route: .purchaseOrder(.index)),
|
|
.hx.target(.id(.purchaseOrder(.table))),
|
|
.hx.swap(.afterBegin),
|
|
.hx.on(.afterRequest, .ifSuccessful(.toggleContent(.float)))
|
|
) {
|
|
div(.class("row")) {
|
|
label(
|
|
.for("customer"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Customer:" }
|
|
input(
|
|
.type(.text), .class("col-3"),
|
|
.name("customer"), .placeholder("Customer"),
|
|
.value(purchaseOrder?.customer ?? ""),
|
|
.required, .autofocus
|
|
)
|
|
label(
|
|
.for("workOrder"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Work Order:" }
|
|
input(
|
|
.type(.text), .class("col-4"),
|
|
.name("workOrder"), .placeholder("Work Order: (12345)"),
|
|
.value("\(purchaseOrder?.workOrder != nil ? String(purchaseOrder!.workOrder!) : "")")
|
|
)
|
|
}
|
|
div(.class("row")) {
|
|
label(
|
|
.for("materials"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Materials:" }
|
|
input(
|
|
.type(.text), .class("col-3"),
|
|
.name("materials"), .placeholder("Materials"),
|
|
.value(purchaseOrder?.materials ?? ""),
|
|
.required
|
|
)
|
|
label(
|
|
.for("vendorBranchID"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Vendor:" }
|
|
if purchaseOrder == nil {
|
|
VendorBranchSelect.purchaseOrderForm()
|
|
} else {
|
|
input(
|
|
.type(.text), .class("col-4"),
|
|
.name("vendorBranchID"),
|
|
.value("\(purchaseOrder!.vendorBranch.vendor.name) - \(purchaseOrder!.vendorBranch.name)"),
|
|
.disabled
|
|
)
|
|
}
|
|
}
|
|
div(.class("row")) {
|
|
label(
|
|
.for("createdForID"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Employee:" }
|
|
if purchaseOrder == nil {
|
|
EmployeeSelect.purchaseOrderForm()
|
|
} else {
|
|
input(
|
|
.type(.text), .class("col-3"),
|
|
.value(purchaseOrder!.createdFor.fullName),
|
|
.disabled
|
|
)
|
|
}
|
|
label(
|
|
.for("truckStock"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
|
) { "Truck Stock:" }
|
|
if purchaseOrder?.truckStock == true {
|
|
input(
|
|
.type(.checkbox), .class("col-2"), .name("truckStock"), .style("margin-top: 20px;"), .checked
|
|
)
|
|
} else {
|
|
input(
|
|
.type(.checkbox), .class("col-2"), .name("truckStock"), .style("margin-top: 20px;")
|
|
)
|
|
}
|
|
}
|
|
if let purchaseOrder, let createdAt = purchaseOrder.createdAt {
|
|
div(.class("row")) {
|
|
label(.class("label col-2")) { "Created:" }
|
|
h3(.class("col-2")) { dateFormatter.string(from: createdAt) }
|
|
if let updatedAt = purchaseOrder.updatedAt {
|
|
div(.class("col-1")) {}
|
|
label(.class("label col-2")) { "Updated:" }
|
|
h3(.class("col-2")) { dateFormatter.string(from: updatedAt) }
|
|
}
|
|
}
|
|
}
|
|
div(.class("btn-row")) {
|
|
button(.class("btn-primary"), .type(.submit)) { buttonLabel }
|
|
if purchaseOrder != nil {
|
|
Button.danger { "Delete" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private var buttonLabel: String {
|
|
guard purchaseOrder != nil else { return "Create" }
|
|
return "Update"
|
|
}
|
|
}
|