Skip to main content

Overview

The Clients module allows you to maintain a comprehensive directory of your business clients. Each client record includes a logo, category assignment, and metadata for organization and display purposes.

Key Features

Logo Management

Upload and store client logos in Supabase Storage

Category Organization

Organize clients by business categories

Pagination

Browse large client lists with configurable page sizes

CRUD Operations

Create, view, update, and delete client records

Adding a New Client

1

Navigate to Clients

Access the Clients module from the sidebar menu.
2

Click 'New Client'

Click the “Agregar Cliente” button to open the creation form.
3

Fill in Client Details

Required fields:
  • Name (nombre): Client company name
  • Category (categoria): Select from existing categories
  • Logo: Upload an image file (PNG, JPG, SVG)
4

Submit the Form

The system will:
  • Validate the input
  • Upload the logo to Supabase Storage
  • Generate the next client ID
  • Insert the record into the database

Logo Upload Process

Logos are stored in Supabase Storage with category-based paths:
clientes.php
$bucket = "clientes";
$nombre_original = basename($_FILES['logo']['name']);
$extension = pathinfo($nombre_original, PATHINFO_EXTENSION);

// Sanitize filename
$nombre_seguro = preg_replace('/[^A-Za-z0-9_-]/', '_', pathinfo($nombre_original, PATHINFO_FILENAME));
$nombre_final = $nombre_seguro . '.' . strtolower($extension);

// Category-based path
$ruta_supabase = "$categoria/logos/$nombre_final";

$contenido = file_get_contents($_FILES['logo']['tmp_name']);

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => "$supabase_url/storage/v1/object/$bucket/$ruta_supabase",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_POSTFIELDS => $contenido,
    CURLOPT_HTTPHEADER => array_merge(get_supabase_headers(), [
        "Content-Type: application/octet-stream"
    ])
]);
$upload_resp = curl_exec($ch);
$upload_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

Storage Path Structure

clientes/
  ├── categoria1/
  │   └── logos/
  │       ├── client1.png
  │       └── client2.jpg
  └── categoria2/
      └── logos/
          └── client3.svg

Client Record Structure

{
  "id": 1,
  "nombre": "Company Name",
  "categoria": 5,
  "logo_url": "categoria1/logos/company.png",
  "created_at": "2024-01-15T10:30:00Z"
}

Pagination

The client list supports pagination for better performance:
clientes.php
$page = intval($_GET['page'] ?? 1);
$perPage = intval($_GET['rowsPerPage'] ?? 10);
$offset = ($page - 1) * $perPage;
Default Settings:
  • Rows per page: 10
  • Configurable: Users can change the page size
  • URL parameters: ?page=2&rowsPerPage=20

Category Integration

Clients are organized by categories defined in the categorias table. Each client must be assigned to a valid category.
Categories help organize clients by industry, service type, or any custom classification system.

Category Selection

When creating or editing a client:
$selected_cat_id = isset($_POST['categoria']) ? intval($_POST['categoria']) : 0;

if (empty($nombre) || $selected_cat_id <= 0) {
    die("<script>alert('❌ Faltan datos requeridos o categoría inválida'); window.history.back();</script>");
}

Editing Clients

To update an existing client:
1

Select Client

Click the edit button next to the client you want to modify.
2

Modify Fields

Update any of the following:
  • Client name
  • Category assignment
  • Logo (optional - upload a new one to replace)
3

Save Changes

Submit the form to update the record in the database.
When uploading a new logo, the old logo file remains in storage. Consider implementing cleanup routines for unused files.

Deleting Clients

Deleting a client:
Deleting a client does not automatically remove their logo from Supabase Storage. The file will remain unless manually deleted.
1

Select Client

Click the delete button for the client you want to remove.
2

Confirm Deletion

Confirm the action in the dialog prompt.
3

Record Removed

The client record is permanently deleted from the database.

Viewing Client Projects

Clients are linked to projects in the Projects module. When viewing a client, you can see all associated projects.

Database Table

Table Name: clientes
ColumnTypeDescription
idintegerAuto-incrementing primary key
nombretextClient company name
categoriaintegerForeign key to categorias.id
logo_urltextStorage path to logo file
created_attimestamptzRecord creation timestamp

API Endpoints

The Clients module uses Supabase REST API:
  • GET /rest/v1/clientes - List all clients
  • POST /rest/v1/clientes - Create new client
  • PATCH /rest/v1/clientes?id=eq.{id} - Update client
  • DELETE /rest/v1/clientes?id=eq.{id} - Delete client

Best Practices

Use consistent logo file formats (PNG or SVG) for better display quality across devices.
Organize categories thoughtfully before adding many clients - restructuring later can be time-consuming.

Troubleshooting

Logo Upload Fails

Possible causes:
  • File size exceeds server limits
  • Invalid file format
  • Insufficient storage permissions
Solution: Check PHP upload_max_filesize and Supabase Storage bucket policies.

Category Not Found

Problem: “Categoría inválida” error Solution: Ensure you’ve selected a valid category from the dropdown. If no categories exist, create one in the Categories module first.

Next Steps

Projects

Link clients to projects

Dashboard

View client statistics