The Home page (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.
/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
- Admin — Despachar Caja
- User — Solicitar Caja
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'.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.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”.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.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.Confirm — Three-Stage API Write
On a valid confirmation the dialog executes three sequential HTTP calls per dispatched product:
POST /ventas/create— creates the parent sale record withuuid_admin,uuid_cliente,total_venta, andfecha(current date).POST /producto-ventas/create— creates a line item withuuid_producto,uuid_venta,cantidad, andtotal_parcial.PUT /productos/edit— decrements stock by writing backstock - quantityalongside the product’suuid,nombre, andprecio.
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
| Method | Endpoint | Purpose |
|---|---|---|
GET | /productos/all | Load beer products with uuid, nombre, precio, stock |
GET | /admin/all | Load all users; filtered to role === 'user' for client dropdown |
GET | /producto-ventas/all | Load all line items to compute totalVenta |
POST | /ventas/create | Create a parent sale record |
POST | /producto-ventas/create | Create a per-product line item |
PUT | /productos/edit | Decrement product stock after dispatch |
Terminar Jornada
The Terminar Jornada button at the bottom of the Home dashboard is rendered only whenuser.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.