diff --git a/ci4/app/Controllers/Logistica/LogisticaController.php b/ci4/app/Controllers/Logistica/LogisticaController.php index f59a0788..7813babd 100644 --- a/ci4/app/Controllers/Logistica/LogisticaController.php +++ b/ci4/app/Controllers/Logistica/LogisticaController.php @@ -68,4 +68,30 @@ class LogisticaController extends BaseController return view(static::$viewPath . 'viewLogisticaSelectEnvios', $viewData); } + public function searchPedidoOrISBN($search = ""){ + + $modelPedido = model('App\Models\Pedidos\PedidoModel'); + + $search = trim($search); + $searchClean = str_replace('-', '', $search); + $modelPedido = model('App\Models\Pedidos\PedidoModel'); + + // Builder con joins + $builder = $modelPedido->builder(); + $builder->select('pedidos.*'); + $builder->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id', 'left'); + $builder->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left'); + + // Agrupar condiciones: por ID exacto o por ISBN sin guiones + $builder->groupStart() + ->where('pedidos.id', $search) + ->orWhere("REPLACE(presupuestos.isbn, '-', '')", $searchClean) + ->groupEnd(); + + $result = $builder->get()->getResult(); + $response = [ + 'status' => true, + 'data' => $result, + ]; + } } diff --git a/ci4/app/Database/Migrations/2025-04-14-193000_CreateEnviosTable.php b/ci4/app/Database/Migrations/2025-04-14-193000_CreateEnviosTable.php new file mode 100644 index 00000000..3ce4cc6d --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-14-193000_CreateEnviosTable.php @@ -0,0 +1,104 @@ +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'); + } +}