Implement bill item service

This commit is contained in:
2025-07-04 16:16:44 +02:00
parent a2b0c7c15e
commit 2e2682e5c5

View File

@@ -0,0 +1,20 @@
import { IndBillitemRecord } from "@/lib/pbtypes";
import { IndJob } from "@/lib/types";
import pb from "@/lib/pocketbase";
import { updateJob } from "./jobService";
export async function addBillItem(
job: IndJob,
billItem: Omit<IndBillitemRecord, 'id' | 'created' | 'updated'>,
type: 'billOfMaterials' | 'consumedMaterials'
): Promise<IndBillitemRecord> {
// Create the bill item
const createdItem = await pb.collection<IndBillitemRecord>('ind_billItem').create(billItem);
const currentBillItems = job[type] || [];
await updateJob(job.id, {
[type]: [...currentBillItems, createdItem.id]
});
return createdItem;
}