Skip to main content

Overview

The Sales module provides comprehensive order management and tracking capabilities. It enables you to monitor sales performance, manage order statuses, and track revenue metrics in real-time.

Order Tracking

Monitor all orders with real-time status updates: Completed, Pending, In Transit, and Returned

Revenue Analytics

Track sales performance with monthly revenue charts and key metrics

Client Relations

Link sales directly to client profiles for better relationship management

Invoice Integration

Automatic invoice generation for completed sales

Venta Model

The Venta model represents sales transactions in the system:
app/Models/Venta.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Venta extends Model
{
    use HasFactory;

    protected $fillable = [
        'numero_orden',
        'cliente_id',
        'producto',
        'total',
        'estado',
    ];

    public function cliente()
    {
        return $this->belongsTo(Cliente::class);
    }

    public function factura()
    {
        return $this->hasOne(Factura::class);
    }
}

Model Relationships

Each sale belongs to a client (belongsTo):
public function cliente()
{
    return $this->belongsTo(Cliente::class);
}
Usage Example:
$venta = Venta::find(1);
$cliente = $venta->cliente;
echo $cliente->nombre; // Access client name

Database Schema

The ventas table structure from the migration:
database/migrations/2026_03_03_191659_create_ventas_table.php
Schema::create('ventas', function (Blueprint $table) {
    $table->id();
    $table->string('numero_orden')->unique();
    $table->foreignId('cliente_id')->constrained('clientes')->onDelete('cascade');
    $table->string('producto');
    $table->decimal('total', 10, 2);
    $table->enum('estado', ['completado', 'pendiente', 'en_camino', 'devuelto'])->default('pendiente');
    $table->timestamps();
});

Table Fields

FieldTypeDescription
idbigintPrimary key
numero_ordenstringUnique order number
cliente_idforeignIdReference to clients table
productostringProduct name/description
totaldecimal(10,2)Total amount
estadoenumOrder status
timestampstimestampscreated_at, updated_at

Order Statuses

The system supports four distinct order statuses to track the complete sales lifecycle.
Completed OrdersOrders that have been successfully fulfilled and delivered to the customer.
Venta::where('estado', 'completado')->get();

Sales View Features

The sales interface (ventas.blade.php) provides:

Dashboard Cards

  • Total Sales: Monthly revenue total ($78,450)
  • Orders: Total order count (342) with growth percentage
  • Pending: Orders awaiting processing (18)
  • Returns: Returned orders this month (5)

Analytics Charts

Monthly Sales Chart

Bar chart showing sales revenue by month (January - June)

Order Status Chart

Pie chart displaying distribution of order statuses

Sales Table

The main sales table displays:
  • Order number (#1045, #1044, etc.)
  • Client name
  • Product description
  • Total amount
  • Order date
  • Status badge (color-coded)
  • Action buttons (View, Cancel)
The table supports real-time search and filtering for quick order lookup.

Usage Examples

Creating a New Sale

use App\Models\Venta;

$venta = Venta::create([
    'numero_orden' => 'ORD-2024-1046',
    'cliente_id' => 1,
    'producto' => 'Laptop Pro',
    'total' => 1500.00,
    'estado' => 'pendiente'
]);

Querying Sales with Client Data

// Get all sales with client information
$ventas = Venta::with('cliente')->get();

foreach ($ventas as $venta) {
    echo $venta->numero_orden . ' - ' . $venta->cliente->nombre;
}

Updating Order Status

$venta = Venta::find(1);
$venta->estado = 'en_camino';
$venta->save();

Sales by Status Report

$completados = Venta::where('estado', 'completado')->count();
$pendientes = Venta::where('estado', 'pendiente')->count();
$en_camino = Venta::where('estado', 'en_camino')->count();
$devueltos = Venta::where('estado', 'devuelto')->count();

Key Features

Unique Order Numbers

Each sale has a unique order identifier for tracking

Client Integration

Direct relationship with client records

Cascade Deletion

Sales are automatically deleted when clients are removed

Decimal Precision

Total amounts stored with 2 decimal precision

Status Tracking

Four-stage order lifecycle monitoring

Timestamp Tracking

Automatic created_at and updated_at timestamps

Build docs developers (and LLMs) love