feat(invoice form): added new invoice form

This commit is contained in:
2025-11-05 21:58:28 -06:00
parent 6ce4d84fd0
commit 65304f61ce
13 changed files with 484 additions and 31 deletions

View File

@@ -53,26 +53,28 @@ router.post("/", async (req: Request, res: Response) => {
}
// this will be the total invoice amount minus each forklift this way we can keep the total amount in here plus forklifts seperated
const totalAmount = (
validatedForklifts.reduce((sum, f) => sum + Number(f.amount || 0), 0) -
req.body.totalInvoice
).toString();
// const totalAmount = (
// validatedForklifts.reduce((sum, f) => sum + Number(f.amount || 0), 0) -
// req.body.totalInvoice
// ).toString();
const { data, error } = await tryCatch(
db
.insert(leaseInvoices)
.values({
...invoiceData,
add_date: sql`NOW()`,
totalAmount: req.body.totalAmount,
uploadedBy: req.user!.username || "lst_user",
})
.onConflictDoUpdate({
target: leaseInvoices.invoiceNumber,
set: {
totalAmount,
invoiceDate: invoiceData.invoiceDate,
uploadedBy: req.user!.username || "lst_user",
},
})
// .onConflictDoUpdate({
// target: leaseInvoices.invoiceNumber,
// set: {
// totalAmount,
// invoiceDate: invoiceData.invoiceDate,
// uploadedBy: req.user!.username || "lst_user",
// },
// })
.returning(),
);
@@ -80,18 +82,21 @@ router.post("/", async (req: Request, res: Response) => {
const err: DrizzleError = error;
return res.status(400).json({
message: `Error adding lease`,
error: err.cause,
// @ts-ignore
error: err.cause.detail,
});
}
const invoiceId = data[0]?.id;
console.log(validatedForklifts);
const forkliftInvoices = validatedForklifts.map((f) => {
return {
invoiceId,
forkliftId: f.forklift_id,
amount: f.amount,
};
});
const forkliftInvoices = validatedForklifts.map((f) => ({
invoiceId,
forkliftId: f.forklift_Id,
amount: f.amount,
}));
console.log(forkliftInvoices);
if (validatedForklifts.length > 0) {
await db.insert(leaseInvoiceForklifts).values(forkliftInvoices);
// .onConflictDoUpdate({

View File

@@ -10,12 +10,14 @@ import { tryCatch } from "../../../../pkg/utils/tryCatch.js";
const router = Router();
router.get("/", async (req: Request, res: Response) => {
const lease = req.query.lease;
const conditions = [];
if (lease !== undefined) {
conditions.push(eq(leases.leaseNumber, `${lease}`));
if (req.query.lease !== undefined) {
conditions.push(eq(leases.leaseNumber, `${req.query.lease}`));
}
if (req.query.companyId !== undefined) {
conditions.push(eq(leases.companyId, `${req.query.companyId}`));
}
//conditions.push(eq(forkliftCompanies.active, true));