Skip to content

Commit bc4360a

Browse files
Implement full employee tracking workflow docs
Add comprehensive docs covering operator setup, shifts, check-in/out, live floor status, and full OEE workflow; fix related batch/hooks adjustments and prepare PR guidance for batch operations integration. X-Lovable-Edit-ID: edt-6bcf61c8-bae0-4f7f-a0c4-be1ed484f87f
2 parents d3513bc + d1f4e17 commit bc4360a

File tree

5 files changed

+446
-21
lines changed

5 files changed

+446
-21
lines changed

src/hooks/useBatches.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function generateBatchNumber(tenantId: string, batchType: string): Promise
6565

6666
export function useBatches(filters?: BatchFilters) {
6767
return useQuery({
68-
queryKey: batchKeys.list(filters),
68+
queryKey: batchKeys.list(filters as Record<string, unknown> | undefined),
6969
queryFn: async () => {
7070
let query = supabase
7171
.from('operation_batches')
@@ -612,16 +612,8 @@ export function useAddOperationToBatch() {
612612

613613
if (error) throw error;
614614

615-
// Update operations count on batch
616-
await supabase.rpc('increment_batch_operations_count', {
617-
p_batch_id: input.batch_id,
618-
}).catch(() => {
619-
// Fallback if RPC doesn't exist
620-
supabase
621-
.from('operation_batches')
622-
.update({ operations_count: supabase.rpc('count_batch_operations', { p_batch_id: input.batch_id }) })
623-
.eq('id', input.batch_id);
624-
});
615+
// The trigger function handles updating operations_count automatically
616+
// No need to call RPC - just return the data
625617

626618
return data as BatchOperation;
627619
},

src/integrations/supabase/types.ts

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,61 @@ export type Database = {
322322
},
323323
]
324324
}
325+
batch_operations: {
326+
Row: {
327+
batch_id: string
328+
created_at: string
329+
id: string
330+
operation_id: string
331+
quantity_in_batch: number | null
332+
sequence_in_batch: number | null
333+
tenant_id: string
334+
updated_at: string | null
335+
}
336+
Insert: {
337+
batch_id: string
338+
created_at?: string
339+
id?: string
340+
operation_id: string
341+
quantity_in_batch?: number | null
342+
sequence_in_batch?: number | null
343+
tenant_id: string
344+
updated_at?: string | null
345+
}
346+
Update: {
347+
batch_id?: string
348+
created_at?: string
349+
id?: string
350+
operation_id?: string
351+
quantity_in_batch?: number | null
352+
sequence_in_batch?: number | null
353+
tenant_id?: string
354+
updated_at?: string | null
355+
}
356+
Relationships: [
357+
{
358+
foreignKeyName: "batch_operations_batch_id_fkey"
359+
columns: ["batch_id"]
360+
isOneToOne: false
361+
referencedRelation: "operation_batches"
362+
referencedColumns: ["id"]
363+
},
364+
{
365+
foreignKeyName: "batch_operations_operation_id_fkey"
366+
columns: ["operation_id"]
367+
isOneToOne: true
368+
referencedRelation: "operations"
369+
referencedColumns: ["id"]
370+
},
371+
{
372+
foreignKeyName: "batch_operations_tenant_id_fkey"
373+
columns: ["tenant_id"]
374+
isOneToOne: false
375+
referencedRelation: "tenants"
376+
referencedColumns: ["id"]
377+
},
378+
]
379+
}
325380
billing_waitlist: {
326381
Row: {
327382
company_name: string
@@ -1921,6 +1976,117 @@ export type Database = {
19211976
},
19221977
]
19231978
}
1979+
operation_batches: {
1980+
Row: {
1981+
actual_time: number | null
1982+
batch_number: string
1983+
batch_type: Database["public"]["Enums"]["batch_type"]
1984+
cell_id: string
1985+
completed_at: string | null
1986+
completed_by: string | null
1987+
created_at: string
1988+
created_by: string | null
1989+
estimated_time: number | null
1990+
external_id: string | null
1991+
external_source: string | null
1992+
id: string
1993+
material: string | null
1994+
nesting_metadata: Json | null
1995+
notes: string | null
1996+
operations_count: number
1997+
started_at: string | null
1998+
started_by: string | null
1999+
status: Database["public"]["Enums"]["batch_status"]
2000+
tenant_id: string
2001+
thickness_mm: number | null
2002+
updated_at: string | null
2003+
}
2004+
Insert: {
2005+
actual_time?: number | null
2006+
batch_number: string
2007+
batch_type?: Database["public"]["Enums"]["batch_type"]
2008+
cell_id: string
2009+
completed_at?: string | null
2010+
completed_by?: string | null
2011+
created_at?: string
2012+
created_by?: string | null
2013+
estimated_time?: number | null
2014+
external_id?: string | null
2015+
external_source?: string | null
2016+
id?: string
2017+
material?: string | null
2018+
nesting_metadata?: Json | null
2019+
notes?: string | null
2020+
operations_count?: number
2021+
started_at?: string | null
2022+
started_by?: string | null
2023+
status?: Database["public"]["Enums"]["batch_status"]
2024+
tenant_id: string
2025+
thickness_mm?: number | null
2026+
updated_at?: string | null
2027+
}
2028+
Update: {
2029+
actual_time?: number | null
2030+
batch_number?: string
2031+
batch_type?: Database["public"]["Enums"]["batch_type"]
2032+
cell_id?: string
2033+
completed_at?: string | null
2034+
completed_by?: string | null
2035+
created_at?: string
2036+
created_by?: string | null
2037+
estimated_time?: number | null
2038+
external_id?: string | null
2039+
external_source?: string | null
2040+
id?: string
2041+
material?: string | null
2042+
nesting_metadata?: Json | null
2043+
notes?: string | null
2044+
operations_count?: number
2045+
started_at?: string | null
2046+
started_by?: string | null
2047+
status?: Database["public"]["Enums"]["batch_status"]
2048+
tenant_id?: string
2049+
thickness_mm?: number | null
2050+
updated_at?: string | null
2051+
}
2052+
Relationships: [
2053+
{
2054+
foreignKeyName: "operation_batches_cell_id_fkey"
2055+
columns: ["cell_id"]
2056+
isOneToOne: false
2057+
referencedRelation: "cells"
2058+
referencedColumns: ["id"]
2059+
},
2060+
{
2061+
foreignKeyName: "operation_batches_completed_by_fkey"
2062+
columns: ["completed_by"]
2063+
isOneToOne: false
2064+
referencedRelation: "profiles"
2065+
referencedColumns: ["id"]
2066+
},
2067+
{
2068+
foreignKeyName: "operation_batches_created_by_fkey"
2069+
columns: ["created_by"]
2070+
isOneToOne: false
2071+
referencedRelation: "profiles"
2072+
referencedColumns: ["id"]
2073+
},
2074+
{
2075+
foreignKeyName: "operation_batches_started_by_fkey"
2076+
columns: ["started_by"]
2077+
isOneToOne: false
2078+
referencedRelation: "profiles"
2079+
referencedColumns: ["id"]
2080+
},
2081+
{
2082+
foreignKeyName: "operation_batches_tenant_id_fkey"
2083+
columns: ["tenant_id"]
2084+
isOneToOne: false
2085+
referencedRelation: "tenants"
2086+
referencedColumns: ["id"]
2087+
},
2088+
]
2089+
}
19242090
operation_day_allocations: {
19252091
Row: {
19262092
cell_id: string
@@ -4106,6 +4272,18 @@ export type Database = {
41064272
Enums: {
41074273
app_role: "operator" | "admin"
41084274
assignment_status: "assigned" | "accepted" | "in_progress" | "completed"
4275+
batch_status:
4276+
| "draft"
4277+
| "ready"
4278+
| "in_progress"
4279+
| "completed"
4280+
| "cancelled"
4281+
batch_type:
4282+
| "laser_nesting"
4283+
| "tube_batch"
4284+
| "saw_batch"
4285+
| "finishing_batch"
4286+
| "general"
41094287
exception_status: "open" | "acknowledged" | "resolved" | "dismissed"
41104288
exception_type: "late" | "early" | "non_occurrence" | "exceeded" | "under"
41114289
expectation_type: "completion_time" | "duration" | "quantity" | "delivery"
@@ -4295,6 +4473,14 @@ export const Constants = {
42954473
Enums: {
42964474
app_role: ["operator", "admin"],
42974475
assignment_status: ["assigned", "accepted", "in_progress", "completed"],
4476+
batch_status: ["draft", "ready", "in_progress", "completed", "cancelled"],
4477+
batch_type: [
4478+
"laser_nesting",
4479+
"tube_batch",
4480+
"saw_batch",
4481+
"finishing_batch",
4482+
"general",
4483+
],
42984484
exception_status: ["open", "acknowledged", "resolved", "dismissed"],
42994485
exception_type: ["late", "early", "non_occurrence", "exceeded", "under"],
43004486
expectation_type: ["completion_time", "duration", "quantity", "delivery"],

src/pages/admin/Batches.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useMemo } from "react";
22
import { useTranslation } from "react-i18next";
3-
import { Plus, Search, Filter, Layers, Play, CheckCircle2, XCircle, Eye, Trash2 } from "lucide-react";
3+
import { Plus, Search, Filter, Layers, Play, CheckCircle2, XCircle, Eye, Trash2, FileEdit, CircleCheck } from "lucide-react";
44
import { Card, CardContent } from "@/components/ui/card";
55
import { Button } from "@/components/ui/button";
66
import { Input } from "@/components/ui/input";
@@ -133,13 +133,12 @@ export default function Batches() {
133133
<div className="space-y-6">
134134
<AdminPageHeader
135135
title={t("batches.title")}
136-
subtitle={t("batches.subtitle")}
137-
action={
138-
<Button onClick={() => setCreateModalOpen(true)} className="cta-button">
139-
<Plus className="h-4 w-4 mr-2" />
140-
{t("batches.createBatch")}
141-
</Button>
142-
}
136+
description={t("batches.subtitle")}
137+
action={{
138+
label: t("batches.createBatch"),
139+
onClick: () => setCreateModalOpen(true),
140+
icon: Plus,
141+
}}
143142
/>
144143

145144
{/* Stats */}
@@ -153,20 +152,24 @@ export default function Batches() {
153152
{
154153
label: t("batches.stats.draft"),
155154
value: stats?.draft || 0,
155+
icon: FileEdit,
156156
},
157157
{
158158
label: t("batches.stats.ready"),
159159
value: stats?.ready || 0,
160+
icon: CircleCheck,
160161
},
161162
{
162163
label: t("batches.stats.inProgress"),
163164
value: stats?.in_progress || 0,
164-
color: "text-status-active",
165+
icon: Play,
166+
color: "warning",
165167
},
166168
{
167169
label: t("batches.stats.completed"),
168170
value: stats?.completed || 0,
169-
color: "text-status-completed",
171+
icon: CheckCircle2,
172+
color: "success",
170173
},
171174
]}
172175
/>

0 commit comments

Comments
 (0)