diff --git a/src/services/billItemService.ts b/src/services/billItemService.ts new file mode 100644 index 0000000..793e120 --- /dev/null +++ b/src/services/billItemService.ts @@ -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, + type: 'billOfMaterials' | 'consumedMaterials' +): Promise { + // Create the bill item + const createdItem = await pb.collection('ind_billItem').create(billItem); + + const currentBillItems = job[type] || []; + await updateJob(job.id, { + [type]: [...currentBillItems, createdItem.id] + }); + + return createdItem; +}