feat(invoices): added invoice + linking to forklift
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { numeric, pgTable, serial, uuid } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { forklifts } from "./forklifts.js";
|
||||
import { leaseInvoices } from "./leaseInvoices.js";
|
||||
|
||||
export const leaseInvoiceForklifts = pgTable("lease_invoice_forklifts", {
|
||||
id: serial("id").primaryKey(),
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
invoiceId: uuid("invoice_id")
|
||||
.notNull()
|
||||
.references(() => leaseInvoices.id, { onDelete: "cascade" }),
|
||||
@@ -12,3 +13,7 @@ export const leaseInvoiceForklifts = pgTable("lease_invoice_forklifts", {
|
||||
.references(() => forklifts.forklift_id, { onDelete: "cascade" }),
|
||||
amount: numeric("amount"), // optional: amount of invoice allocated to this lift
|
||||
});
|
||||
|
||||
export const newForkliftInvoiceSchema = createInsertSchema(
|
||||
leaseInvoiceForklifts,
|
||||
);
|
||||
|
||||
@@ -23,7 +23,7 @@ const status = pgEnum("forklift_status", [
|
||||
export const forklifts = pgTable("forklifts", {
|
||||
forklift_id: uuid("forklift_id").defaultRandom().primaryKey(),
|
||||
forkliftNumber: serial("forklift_number").notNull(),
|
||||
serialNumber: text("serial_number").notNull(),
|
||||
serialNumber: text("serial_number").unique().notNull(),
|
||||
model: text("model").notNull(),
|
||||
plant: text("plant")
|
||||
.notNull()
|
||||
@@ -41,8 +41,8 @@ export const forklifts = pgTable("forklifts", {
|
||||
dataPlate: text("data_plate"),
|
||||
add_date: timestamp("add_date").defaultNow(),
|
||||
add_user: text("add_user").default("LST"),
|
||||
upd_date: timestamp("add_date").defaultNow(),
|
||||
upd_user: text("add_user").default("LST"),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
upd_user: text("upd_user").default("LST"),
|
||||
});
|
||||
|
||||
export const forkliftsSchema = createSelectSchema(forklifts);
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
import { date, numeric, pgTable, text, uuid } from "drizzle-orm/pg-core";
|
||||
import { forkliftCompanies } from "./forkliftLeaseCompanys.js";
|
||||
import {
|
||||
date,
|
||||
numeric,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { leases } from "./forkliftLeases.js";
|
||||
import { forklifts } from "./forklifts.js";
|
||||
|
||||
export const leaseInvoices = pgTable("lease_invoices", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
leaseId: uuid("lease_id")
|
||||
.notNull()
|
||||
.references(() => leases.id, { onDelete: "cascade" }),
|
||||
companyId: uuid("company_id").references(() => forkliftCompanies.id),
|
||||
invoiceNumber: text("invoice_number").notNull(),
|
||||
invoiceNumber: text("invoice_number").unique().notNull(),
|
||||
invoiceDate: date("invoice_date").notNull(),
|
||||
forkliftId: uuid("forklift_id")
|
||||
.notNull()
|
||||
.references(() => forklifts.forklift_id, { onDelete: "cascade" }),
|
||||
totalAmount: numeric("total_amount"),
|
||||
add_date: timestamp("add_date"),
|
||||
uploadedBy: text("uploaded_by"),
|
||||
});
|
||||
|
||||
export const newInvoiceSchema = createInsertSchema(leaseInvoices);
|
||||
|
||||
Reference in New Issue
Block a user