Merge branch 'main' into feat/view-maquinista

This commit is contained in:
amazuecos
2025-04-22 10:34:06 +02:00
41 changed files with 4024 additions and 1586 deletions

View File

@ -0,0 +1,104 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateEnviosTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'finalizado' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'codigo_seguimiento' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => true,
],
'proveedor_id' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
],
'comentarios' => [
'type' => 'TEXT',
'null' => true,
],
'att' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => true,
],
'direccion' => [
'type' => 'VARCHAR',
'constraint' => 300,
'null' => true,
],
'ciudad' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => true,
],
'cp' => [
'type' => 'VARCHAR',
'constraint' => 10,
'null' => true,
],
'email' => [
'type' => 'VARCHAR',
'constraint' => 150,
'null' => true,
],
'telefono' => [
'type' => 'VARCHAR',
'constraint' => 60,
'null' => true,
],
'pais_id' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
],
'mostrar_precios' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'mostrar_iva' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'created_at' => [
'type' => 'TIMESTAMP',
'null' => false,
'default' => '0000-00-00 00:00:00',
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => false,
'default' => '0000-00-00 00:00:00',
],
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('proveedor_id', 'lg_proveedores', 'id', 'SET NULL', 'SET NULL');
$this->forge->addForeignKey('pais_id', 'lg_paises', 'id', 'SET NULL', 'SET NULL');
$this->forge->createTable('envios');
}
public function down()
{
$this->forge->dropTable('envios');
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class AddMEnvioColumns extends Migration
{
public function up()
{
$this->forge->addColumn("envios",
["multienvio" => [
"type" => "TINYINT",
"unsigned" => true,
"null" => false,
"default" => 0,
]]
);
}
public function down()
{
$this->forge->dropColumn("envios", ['multienvio']);
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddEnviosLineas extends Migration
{
public function up()
{
$this->forge->addField([
'id' => ['type' => 'INT', 'auto_increment' => true],
'envio_id' => ['type' => 'INT', 'unsigned' => true],
'pedido_id' => ['type' => 'INT', 'unsigned' => true],
'presupuesto_id' => ['type' => 'INT', 'unsigned' => true],
'unidades_envio' => ['type' => 'INT', 'default' => 0],
'unidades_total' => ['type' => 'INT', 'default' => 0],
'cajas' => ['type' => 'INT', 'default' => 0],
'unidades_cajas' => ['type' => 'INT', 'default' => 0],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
'created_by' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
'updated_by' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
]);
$this->forge->addKey('id', true); // Primary Key
// Foreign Keys
$this->forge->addForeignKey('presupuesto_id', 'presupuestos', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('pedido_id', 'pedidos', 'id', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('created_by', 'users', 'id', 'SET NULL', 'CASCADE');
$this->forge->addForeignKey('updated_by', 'users', 'id', 'SET NULL', 'CASCADE');
$this->forge->createTable('envios_lineas');
}
public function down()
{
$this->forge->dropTable('envios_lineas');
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class ModifyAlbaranesAndAlbaranesLineas extends Migration
{
public function up()
{
// --- Tabla albaranes ---
$this->forge->dropColumn('albaranes', [
'pedido_id',
'presupuesto_id',
'presupuesto_direccion_id',
'total'
]);
$this->forge->addColumn('albaranes', [
'fecha_albaran' => [
'type' => 'DATE',
'null' => true,
'after' => 'numero_albaran'
],
'envio_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
'after' => 'fecha_albaran'
]
]);
// Añadir foreign key a envios con ON DELETE SET NULL
$this->db->query('ALTER TABLE `albaranes`
ADD CONSTRAINT `fk_albaranes_envio_id` FOREIGN KEY (`envio_id`)
REFERENCES `envios`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
// --- Tabla albaranes_lineas ---
$this->forge->dropColumn('albaranes_lineas', ['cajas', 'ejemplares_por_caja']);
$this->forge->addColumn('albaranes_lineas', [
'iva_reducido' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
'null' => false,
'after' => 'precio_unidad'
]
]);
}
public function down()
{
// Deshacer cambios tabla albaranes
$this->forge->dropForeignKey('albaranes', 'fk_albaranes_envio_id');
$this->forge->dropColumn('albaranes', ['envio_id', 'fecha_albaran']);
$this->forge->addColumn('albaranes', [
'pedido_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
],
'presupuesto_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
],
'presupuesto_direccion_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
],
'total' => [
'type' => 'DOUBLE',
'null' => true,
],
]);
// Deshacer cambios tabla albaranes_lineas
$this->forge->dropColumn('albaranes_lineas', ['iva_reducido']);
$this->forge->addColumn('albaranes_lineas', [
'cajas' => [
'type' => 'INT',
'null' => true,
],
'ejemplares_por_caja' => [
'type' => 'INT',
'null' => true,
],
]);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddClienteIdToEnvios extends Migration
{
public function up()
{
$this->forge->addColumn('envios', [
'cliente_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true, // IMPORTANTE
'null' => true,
'after' => 'id',
],
]);
$this->db->query('ALTER TABLE envios ADD CONSTRAINT fk_envios_cliente FOREIGN KEY (cliente_id) REFERENCES clientes(id) ON DELETE SET NULL ON UPDATE CASCADE');
}
public function down()
{
$this->db->query('ALTER TABLE envios DROP FOREIGN KEY fk_envios_cliente');
$this->forge->dropColumn('envios', 'cliente_id');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class RenameCajasNullable extends Migration
{
public function up()
{
$this->forge->modifyColumn('envios_lineas', [
'cajas' => [
'type' => 'INT',
'constraint' => 11,
'null' => true,
'default' => null,
],
]);
}
public function down()
{
$this->forge->modifyColumn('envios_lineas', [
'cajas' => [
'type' => 'INT',
'constraint' => 11,
'null' => false,
'default' => 0,
],
]);
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class UpdateEnviosAlbaranes extends Migration
{
public function up()
{
// 1. Quitar columnas de envios_lineas
$this->forge->dropColumn('envios_lineas', ['cajas', 'unidades_cajas']);
// 2. Añadir columna 'cajas' en envios
$this->forge->addColumn('envios', [
'cajas' => [
'type' => 'INT',
'constraint' => 11,
'default' => 0,
'after' => 'comentarios'
]
]);
// 2. Quitar columna multienvio de envios
$this->forge->dropColumn('envios', 'multienvio');
// 3. Añadir columna 'cajas' en albaranes
$this->forge->addColumn('albaranes', [
'cajas' => [
'type' => 'INT',
'constraint' => 11,
'default' => 0,
'after' => 'envio_id'
]
]);
// 4. Añadir columna 'pedido_linea_id' a albaranes_lineas
$this->forge->addColumn('albaranes_lineas', [
'pedido_linea_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
'after' => 'albaran_id'
]
]);
// 5. Foreign key a pedidos_lineas
$this->db->query("
ALTER TABLE albaranes_lineas
ADD CONSTRAINT fk_albaranes_lineas_pedido_linea
FOREIGN KEY (pedido_linea_id) REFERENCES pedidos_linea(id)
ON DELETE SET NULL ON UPDATE CASCADE
");
}
public function down()
{
// Revertir cajas en envios_lineas
$this->forge->addColumn('envios_lineas', [
'cajas' => [
'type' => 'INT',
'constraint' => 11,
'null' => true,
],
'unidades_cajas' => [
'type' => 'INT',
'constraint' => 11,
'null' => true,
]
]);
$this->forge->addColumn('envios', [
'multienvio' => [
'type' => 'TINYINT',
'constraint' => 3,
'unsigned' => true,
'default' => 0
]
]);
// Quitar columnas añadidas
$this->forge->dropColumn('envios', 'cajas');
$this->forge->dropColumn('albaranes', 'cajas');
// Quitar foreign y columna pedido_linea_id
$this->db->query("ALTER TABLE albaranes_lineas DROP FOREIGN KEY fk_albaranes_lineas_pedido_linea");
$this->forge->dropColumn('albaranes_lineas', 'pedido_linea_id');
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class FixDeletedAtToDatetime extends Migration
{
public function up()
{
// Cambia los tipos de deleted_at a DATETIME NULL si existen
$tablas = ['albaranes', 'albaranes_lineas', 'envios', 'envios_lineas'];
foreach ($tablas as $tabla) {
$this->db->query("ALTER TABLE {$tabla} MODIFY COLUMN deleted_at DATETIME NULL");
}
}
public function down()
{
// Opcional: puedes restaurar como TIMESTAMP NULL si lo deseas
$tablas = ['albaranes', 'albaranes_lineas', 'envios', 'envios_lineas'];
foreach ($tablas as $tabla) {
$this->db->query("ALTER TABLE {$tabla} MODIFY COLUMN deleted_at TIMESTAMP NULL");
}
}
}