Overview
Each daily operation records:- Date and meal shift (Desayuno, Almuerzo, Merienda)
- Student attendance count
- Products cooked for the meal
Automatic calculation: The system calculates how much of each ingredient to deduct based on attendance and portion recipes, then deducts from the oldest batches first (FIFO).
Creating a Daily Operation
Step 1: Basic Information
Date of the operationDefault: Current date using
getLocalDate()Meal shift:
Desayuno- BreakfastAlmuerzo- LunchMerienda- Snack
(fecha, turno) combination must be uniqueNumber of students attendingExample: 774Minimum: 1
Step 2: Select Products to Cook
Click ”+ Agregar Rubro” to add products used in the meal.Product Selection
For each product row:- Dropdown: Shows products with portion recipes, displaying current stock
- Validation: Cannot select the same product twice
- Live calculation: Shows required quantity based on attendance
Quantity Calculation
The system calculates required amount automatically:- Product: Arroz (Rice)
- Rendimiento: 12 porciones por kg (12 portions per kg)
- Attendance: 774 students
- Calculation: 774 / 12 = 64.50 kg needed
Stock Validation
Each product row shows:✅ Sufficient Stock
Green indicator: “64.50 kg necesarios”Stock is adequate to fulfill the order
⚠️ Insufficient Stock
Red indicator: “64.50 kg necesarios (stock: 30.00)”Not enough inventory - operation will fail
Step 3: Submit Operation
Click “Registrar Operación” to process.Processing Logic (FIFO)
When submitted, the system calls theprocesar_operacion_diaria RPC function (supabase_schema.sql:571-706):
FIFO Batch Consumption
The function queries all approved batches for the product, ordered by expiration date (oldest first):Then consumes from batches sequentially:
Deduct from Product Stock
Creates an
output record which triggers the update_stock_on_output trigger:Error Handling
Viewing Operations History
The page shows the 50 most recent operations in a table.Table Columns
| Column | Description | Data |
|---|---|---|
| Fecha | Operation date | registro_diario.fecha |
| Turno | Meal shift badge | Desayuno / Almuerzo / Merienda |
| Asistencia | Student count | ”774 alumnos” |
| Registrado por | User who created | users.full_name (joined) |
| Notas | Optional notes | registro_diario.notas |
| Detalle | Expand/collapse button | Shows products consumed |
Expandable Details
Click ”▼ Ver rubros” to expand and see consumed products:output table:
Data Structure
registro_diario Table
output Table (Linked Details)
Trigger on output: Inserting into
output automatically triggers update_stock_on_output() which deducts from product.stock and validates availability.receta_porcion Table
| id_product | Product Name | rendimiento_por_unidad | unit_measure |
|---|---|---|---|
| 1 | Arroz | 12.00 | kg |
| 3 | Leche en polvo | 40.00 | kg |
| 4 | Pollo | 4.00 | kg |
| 5 | Caraotas negras | 10.00 | kg |
- 1 kg of rice yields 12 portions
- 1 kg of powdered milk yields 40 portions
- 1 kg of chicken yields 4 portions
Role-Based Access
| Role | Create Operations | View History |
|---|---|---|
| Director (id_rol=1) | ✅ | ✅ |
| Madre Procesadora (id_rol=2) | ✅ | ✅ |
| Supervisor (id_rol=3) | ❌ | ✅ |
| Desarrollador (id_rol=4) | ✅ | ✅ |
FIFO Batch Tracking
The FIFO implementation uses thelotes_detalle JSONB field in the input table.
Before Operation
Product: Arroz (Rice)Stock: 150 kg Batches:
| id_input | Guía | Batch Data (JSONB) |
|---|---|---|
| 101 | 89 | [{"cantidad": 50, "fecha_vencimiento": "2026-06-30"}] |
| 102 | 90 | [{"cantidad": 60, "fecha_vencimiento": "2026-09-15"}, {"cantidad": 40, "fecha_vencimiento": "2026-12-31"}] |
After Operation (64.50 kg consumed)
FIFO consumes oldest first:- Batch from id_input=101: Expires 2026-06-30 → Consume 50 kg
- Batch from id_input=102: Expires 2026-09-15 → Consume 14.50 kg
| id_input | Batch Data (JSONB) |
|---|---|
| 101 | [{"cantidad": 0, "fecha_vencimiento": "2026-06-30"}] |
| 102 | [{"cantidad": 45.50, "fecha_vencimiento": "2026-09-15"}, {"cantidad": 40, "fecha_vencimiento": "2026-12-31"}] |
Technical Details
File location:
src/pages/RegistroDiario.jsx:1-407Key Functions
- loadRegistros(): Fetches last 50 operations with creator info
- loadProductosConRendimiento(): Gets products that have portion recipes configured
- loadDetallesRegistro(): On-demand fetch of consumed products when expanding a row
- getCalculoRubro(): Real-time calculation of required quantity based on attendance
- handleSubmit(): Calls
procesar_operacion_diariaRPC
Form Validation
- Prevents duplicate product selection
- Requires at least one product
- Shows live stock availability warnings
- Validates that portion recipes exist
Use Cases
Daily Meal Tracking
Record each meal service with accurate attendance and ingredient usage
FIFO Compliance
Automatically consume oldest batches first to minimize food waste
Inventory Accuracy
Real-time stock deduction ensures inventory data reflects actual usage
Audit Trail
Complete history of all operations with expandable details for transparency