DEV Community

Roberto Luna
Roberto Luna

Posted on

Implementing Quotation from Materials and Scheduled Maintenance in Riviera Industrial ERP

Implementing Quotation from Materials and Scheduled Maintenance in Riviera Industrial ERP

 

TL;DR: I added features to generate quotes from materials and scheduled maintenance to the Riviera Industrial ERP. This involved updating the Prisma schema, implementing new API routes, and modifying existing components.

The Problem

The Riviera Industrial ERP lacked the functionality to generate quotes directly from materials and to manage scheduled maintenance. This resulted in manual workarounds and inefficiencies in the quoting process and maintenance planning.

What I Tried First

Initially, I attempted to extend the existing quote functionality to include material-based quoting. However, this approach led to complexities in handling the relationships between materials, quotes, and production processes. I then decided to refactor the Prisma schema to better support these new features.

The Implementation

Updating the Prisma Schema

I modified the prisma/schema.prisma file to include new models and relationships for materials and maintenance:

model QuoteItem {
  unitPrice     Decimal            @default(0) @db.Decimal(12, 2)
  total         Decimal            @default(0) @db.Decimal(12, 2)
  process       ProductionProcess?   @relation(fields: [processId], references: [id])
  // ...
}

model MaintenanceOrder {
  id            String             @id @default(cuid())
  description   String
  scheduledAt   DateTime
  // ...
}
Enter fullscreen mode Exit fullscreen mode

New API Routes

I created a new API route for generating quotes from materials in src/app/api/quotes/route.ts:

export async function POST(req: NextRequest) {
  const { materialId, quantity } = await req.json();
  const material = await getMaterial(materialId);
  const unitPrice = material.unitPrice;
  const total = unitPrice * quantity;

  // Create a new quote item
  const quoteItem = await prisma.quoteItem.create({
    data: {
      description: material.description,
      unitPrice,
      total,
      // ...
    },
  });

  return NextResponse.json({ quoteItem });
}
Enter fullscreen mode Exit fullscreen mode

Maintenance Pages

I added new pages for managing maintenance orders in src/app/operations/maintenance/[id]/page.tsx, src/app/operations/maintenance/new/page.tsx, and src/app/operations/maintenance/page.tsx.

Component Updates

I updated the src/components/shared/NewQuoteForm.tsx component to include material-based quoting:

import { listMaterials } from "@/server/repositories/materials";

export default function NewQuoteForm() {
  const [materials, setMaterials] = useState([]);

  useEffect(() => {
    listMaterials().then((data) => setMaterials(data));
  }, []);

  // ...
}
Enter fullscreen mode Exit fullscreen mode

Key Takeaway

The key takeaway from this implementation is the importance of carefully planning and executing schema changes and API routes when adding new features to an existing application.

What's Next

Next, I plan to integrate WhatsApp notifications for quote requests and maintenance orders. This will involve setting up a WhatsApp API and modifying the existing notification system.

vibecoding #buildinpublic #rivera-industrial-erp #quotation-system #maintenance-management


Part of my Build in Public series — sharing the real process of building Building Riviera Industrial ERP from Playa del Carmen, México.

Repo: zaerohell/riviera-industrial-erp · 2026-07-01

#playadev #buildinpublic

Top comments (0)