Overview
The sales tracking system (Ventas) manages all purchase transactions, including product sales, promotional sales, payment processing, and comprehensive reporting for both vendors and administrators.Sales Record Structure
Venta (Sale) Fields
| Field | Type | Description |
|---|---|---|
id_venta | int | Unique transaction identifier |
register_idregistro | int | Customer ID (buyer) |
galeria_id_galeria | int | Product ID (if product sale) |
promocion_id_promo | int | Promotion ID (if promo sale) |
locale_id_local | int | Store/vendor ID |
fecha | varchar(45) | Transaction date |
cantidad | int | Quantity purchased |
cuantos | int | Order number/counter |
status | int | Order status (3=completed) |
forma_pago | varchar(255) | Payment method |
numero_pago | varchar(255) | Payment reference number |
Model Relationships
Purchase Flow
Product Purchase Process
Customer Selects Product
Customer browses products and clicks to purchaseValidation: System checks if product is available (
cantidad_existente > 0)Consultation Check
AJAX call to
/ventas/consulta/{product}/{customer}/{store}Returns:2- Product out of stock3- Product available, can purchase4- Customer already has pending order for this product
Add to Cart
If available, customer specifies quantity and adds to cartAJAX Endpoint:
/ventas/add/{product}/{customer}/{store}/{quantity}/{order_count}Cart System
Yoneily uses a simplified cart system where sales are recorded immediately but marked with a status. The
cuantos field tracks the order sequence./ventas/carrito/{store_id}/{customer_id}/{order_count}
Displays:
- All products from the selected store
- All promotions from the store
- Pagination (8 items per page)
- Store information
Promotional Sales
Promotions follow a similar flow to products: Key Differences:- Uses
promocion_id_promoinstead ofgaleria_id_galeria - Updates promotion stock instead of product stock
- Separate consultation endpoint:
/ventas/consulta_promocion - Add endpoint:
/ventas/add_promo
Payment Processing
Finalizing Purchase
Endpoint:/ventas/finalizar_compra/{payment_method}/{payment_number}/{sale_id}
Process:
- Customer selects payment method
- Enters payment reference number
- System updates sale record:
- Returns status code
6on success
Payment Methods
The system supports multiple payment options configured per store:Bank Transfer
Customer transfers to vendor’s bank account
Credit Card
Online card processing (if enabled)
Cash on Delivery
Payment upon product delivery
Customer Purchase History
My Purchases (Mis Compras)
Endpoint:/ventas/miscompras
Features:
- Displays customer’s purchase history
- Pagination (6 transactions per page)
- Ordered by date (newest first)
- Shows:
- Product/promo details
- Store information
- Quantity and price
- Purchase date
- Payment status
My Messages (Mis Mensajes)
Endpoint:/ventas/mismensajes
Displays customer communications with vendors:
- Product inquiries
- Store responses
- Status indicators
- Pagination (8 messages per page)
My Complaints (Mis Reclamos)
Endpoint:/ventas/misreclamos
Shows customer’s submitted complaints and responses:
- Complaint details
- Vendor responses (
resp != 0) - Store information
- Status tracking
- Pagination (8 items per page)
These views use complex JOIN queries to combine data from
Denuncia, Gallery, Promo, and Locale tables.Sales Reporting
Administrator Sales List
Endpoint:/ventas/index
Features:
- View all sales across all stores
- Pagination (10 records per page)
- Ordered by date (DESC)
- Related data loaded automatically
- Customer information
- Product/promotion details
- Store information
- Payment details
- Transaction dates
PDF Generation
- Single Purchase Receipt
- Daily Sales Report
Route:
/ventas/pdf_compra/{id}Generates:- Individual transaction receipt
- Product/promo details
- Customer information
- Payment method and reference
- Store contact details
PDF Configuration
Inventory Integration
Stock Updates
Every sale automatically triggers inventory updates:Out of Stock Handling
Response Codes:0- Database error1- Success2- Out of stock4- Duplicate order (customer already has pending order)
Sales Statistics
Transaction Counter
Endpoint:/ventas/cuantos
Returns total number of sales in the system (all time).
Usage: Display dashboard statistics or track order numbers.
Sales Analysis
Query sales data for business intelligence:Customer Interaction
Complaint Filing
Customers can file complaints about purchases: Endpoint:/ventas/denunciar/{product}/{customer}/{store}
Process:
- Customer selects product to complain about
- Form opens with pre-filled details
- Customer enters complaint text
- Submitted to
/ventas/finalizar_denunciar - Complaint record created in
denunciastable
Complaints are covered in detail in the Complaints System documentation.
AJAX Endpoints
Consultation System
All purchase validation happens via AJAX for instant feedback:Product Consultation
Product Consultation
Route:
/ventas/consulta/{product}/{customer}/{store}Returns:2- Out of stock3- Available4- Pending order exists
Promotion Consultation
Promotion Consultation
Route:
/ventas/consulta_promocion/{product}/{customer}/{store}Returns: Same codes as product consultationAdd to Cart
Add to Cart
Route:
/ventas/add_carrito/{product}/{customer}/{store}/{quantity}/{order}Returns:0- Database error1- Success2- Out of stock
Access Control
Public Endpoints
The following actions are accessible without login:Protected Actions
Administrator-only endpoints:index- View all salesview- View sale detailspdf_completo_venta- Generate comprehensive reportsdeleteoperations
Best Practices
Transaction Integrity
Transaction Integrity
- Always validate stock before sale
- Use database transactions for multi-step operations
- Update inventory atomically with sale creation
- Log all transaction changes
Customer Experience
Customer Experience
- Provide immediate feedback on stock availability
- Clear error messages for out-of-stock items
- Prevent duplicate orders for same product
- Send confirmation after payment
Reporting
Reporting
- Generate PDFs on-demand, not pre-cached
- Include all relevant transaction details
- Provide date-range filtering for reports
- Export options for accounting integration
Related Features
Inventory Management
Product stock and pricing
Promotions
Promotional campaigns
Complaints System
Customer feedback handling
Technical Notes
Date Format
Sales dates are stored as strings ind-m-Y format:
Sale Status Codes
| Status | Description |
|---|---|
| NULL | Incomplete/pending |
| 3 | Completed with payment |