Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Edwin950821/BodegaX/llms.txt

Use this file to discover all available pages before exploring further.

The Home page (/home) is BodegaX’s primary sales dashboard — called Venta in the interface. On load it fetches all products and clients, then computes a running totalVenta by summing every cantidad value returned from GET /producto-ventas/all. Because BodegaX serves two distinct roles, the same page adapts its controls at runtime: administrators see a Despachar Caja (Dispatch Crate) button to fulfil orders on behalf of clients, while standard users see a Solicitar Caja (Request Crate) button to submit their own requests. Both roles click the same button element — the buttonRole getter simply changes the label. Admins also have access to the orange Terminar Jornada button, which triggers the end-of-day PDF report.

Dashboard at a Glance

Total Cajas Vendidas / Solicitadas

The totalVenta counter aggregates all cantidad values from GET /producto-ventas/all. Each line item is joined to its product name via uuid_producto for display purposes, but the counter itself is a simple running sum.

Sales Detail Table

The Detalles table attempts to render a *ngFor loop over the ventas array and also includes one hardcoded static row for Butweiser (6). The ventas property is declared but never populated by ngOnInit, so only the static row reliably appears in the current implementation.

Role-Adaptive Button

The buttonRole getter returns 'Despachar Caja' when user.role !== 'user' and 'Solicitar Caja' for users. Both labels invoke the same solicitarCajas() method, which always opens the DespacharCaja dialog — the difference is in how the client list passed to the dialog is filtered.

Terminar Jornada

Visible only when user.role === 'admin' (checked against the sessionStorage value), this orange button opens the TerminarJornada dialog to generate and download the day’s PDF report.

Role-Based Flows

Administrators dispatch crate sales directly to clients. Clicking the blue Despachar Caja button calls solicitarCajas(), which opens the DespacharCaja dialog with the full product list and all clients whose role === 'user'.
1

Open the Dispatch Dialog

Click the blue Despachar Caja button. During ngOnInit, the component calls GET /admin/all and filters the results to role === 'user' before storing them in this.clientes. The full this.clientes list and this.productos are passed to the DespacharCaja dialog.
2

Select a Client

Choose a client from the dropdown. The dialog binds the selection to clienteSelected. Attempting to confirm without a client triggers an alert: “Debe escoger cliente y la venta no puede ser 0”.
3

Enter Quantities per Product

For each beer product displayed, enter the number of crates to dispatch. The validVenta() method accumulates p.precio * p.quantity for every product where quantity > 0.
4

Stock Validation

Before the order is submitted, validVenta() checks every product. If any quantity > stock, the method immediately alerts the user and returns 0, preventing the request from proceeding.
5

Confirm — Three-Stage API Write

On a valid confirmation the dialog executes three sequential HTTP calls per dispatched product:
  1. POST /ventas/create — creates the parent sale record with uuid_admin, uuid_cliente, total_venta, and fecha (current date).
  2. POST /producto-ventas/create — creates a line item with uuid_producto, uuid_venta, cantidad, and total_parcial.
  3. PUT /productos/edit — decrements stock by writing back stock - quantity alongside the product’s uuid, nombre, and precio.
The dialog closes with true once the final product’s write completes.

Stock Validation Rules

The validVenta() method enforces two hard rules before any API call is made. First, if quantity > stock for any product, a browser alert fires immediately and the entire dispatch is blocked — no partial orders are created. Second, if the accumulated totalVenta equals 0 or no client has been selected (clienteSelected === ''), the same blocking alert appears. Both conditions must be satisfied for the order to proceed.

API Reference

MethodEndpointPurpose
GET/productos/allLoad beer products with uuid, nombre, precio, stock
GET/admin/allLoad all users; filtered to role === 'user' for client dropdown
GET/producto-ventas/allLoad all line items to compute totalVenta
POST/ventas/createCreate a parent sale record
POST/producto-ventas/createCreate a per-product line item
PUT/productos/editDecrement product stock after dispatch

Terminar Jornada

The Terminar Jornada button at the bottom of the Home dashboard is rendered only when user.role === 'admin'. Clicking it opens the TerminarJornada dialog, passing this.clientes as the client list. The dialog independently loads all sales and product data and allows the admin to generate a PDF report for a selected client. See the End-of-Day Report page for the full PDF generation workflow.
The Home component listens to window.resize events and toggles isMobile when the viewport crosses 768 px. On mobile, the sidebar collapses automatically to maximise the sales dashboard’s available width.

Build docs developers (and LLMs) love