diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 23a7d20f..21a5d3db 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -464,7 +464,7 @@ class Cliente extends \App\Controllers\BaseResourceController return null; } $modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel'); - $plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first(); + $plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("deleted_at", null)->first(); if ($plantilla == false) { return null; } else { diff --git a/ci4/app/Controllers/Clientes/ClientePrecios.php b/ci4/app/Controllers/Clientes/ClientePrecios.php index 61cfb986..49a0b4bf 100755 --- a/ci4/app/Controllers/Clientes/ClientePrecios.php +++ b/ci4/app/Controllers/Clientes/ClientePrecios.php @@ -135,7 +135,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController Field::inst('tipo_impresion'), Field::inst('user_updated_id'), Field::inst('updated_at'), - Field::inst('is_deleted'), Field::inst('tiempo_min') ->getFormatter('Format::toDecimalChar')->setFormatter('Format::fromDecimalChar') ->validator( @@ -205,7 +204,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) { foreach ($data['data'] as $pkey => $values) { // Si no se quiere borrar... - if ($data['data'][$pkey]['is_deleted'] != 1) { $process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min']; $process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max']; $process_data['tipo'] = $data['data'][$pkey]['tipo']; @@ -217,7 +215,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController if (!empty($response)) { return $response; } - } } } }) diff --git a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php index d0b4d98a..f5a29dbc 100755 --- a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php +++ b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php @@ -155,7 +155,6 @@ class Clienteplantillaprecioslineas extends \App\Controllers\BaseResourceControl Field::inst( 'tipo_impresion' ), Field::inst( 'user_updated_id' ), Field::inst( 'deleted_at' ), - Field::inst( 'is_deleted' ), Field::inst( 'updated_at' ), Field::inst( 'tiempo_min' ) ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') diff --git a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php new file mode 100644 index 00000000..db9b6c88 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php @@ -0,0 +1,74 @@ +db->table('clientes'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('clientes',"is_deleted"); + + $m = $this->db->table('cliente_contactos'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_contactos',"is_deleted"); + + $m = $this->db->table('cliente_precios'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_precios',"is_deleted"); + + $m = $this->db->table('cliente_plantilla_precios_lineas'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_plantilla_precios_lineas',"is_deleted"); + + $m = $this->db->table('cliente_plantilla_precios'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_plantilla_precios',"is_deleted"); + + + } + + public function down() + { + $column = [ + 'is_deleted' => [ + 'type' => 'BOOLEAN', + 'default' => false, + ], + ]; + $this->forge->addColumn('clientes',$column); + $m = $this->db->table('clientes'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_contactos',$column); + $m = $this->db->table('cliente_contactos'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_precios',$column); + $m = $this->db->table('cliente_precios'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_plantilla_precios_lineas',$column); + $m = $this->db->table('cliente_plantilla_precios_lineas'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_plantilla_precios',$column); + $m = $this->db->table('cliente_plantilla_precios'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + } +} diff --git a/ci4/app/Models/Clientes/ClienteContactoModel.php b/ci4/app/Models/Clientes/ClienteContactoModel.php index 5338f71a..5571db67 100755 --- a/ci4/app/Models/Clientes/ClienteContactoModel.php +++ b/ci4/app/Models/Clientes/ClienteContactoModel.php @@ -25,12 +25,12 @@ class ClienteContactoModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClienteContactoEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; protected $updatedField = "updated_at"; - protected $deletedField = 'deleted_at'; public static $labelField = "nombre"; @@ -113,7 +113,7 @@ class ClienteContactoModel extends \App\Models\BaseModel ); $builder->where('t1.cliente_id', $cliente_id); - $builder->where("t1.is_deleted", 0); + $builder->where("t1.deleted_at", null); $builder->join("clientes t2", "t1.cliente_id = t2.id", "left"); return empty($search) diff --git a/ci4/app/Models/Clientes/ClienteModel.php b/ci4/app/Models/Clientes/ClienteModel.php index 12df2831..57de29a4 100755 --- a/ci4/app/Models/Clientes/ClienteModel.php +++ b/ci4/app/Models/Clientes/ClienteModel.php @@ -2,6 +2,8 @@ namespace App\Models\Clientes; +use App\Entities\Clientes\ClienteEntity; + class ClienteModel extends \App\Models\BaseModel { protected $table = "clientes"; @@ -57,13 +59,11 @@ class ClienteModel extends \App\Models\BaseModel "comentarios_tirada_flexible", "margen_plantilla_id", "comentarios", - "is_deleted", - "deleted_at", "user_created_id", "user_update_id", ]; - protected $returnType = "App\Entities\Clientes\ClienteEntity"; - + protected $returnType = ClienteEntity::class; + protected $useSoftDeletes = true; protected $deletedField = 'deleted_at'; public static $labelField = "nombre"; @@ -197,10 +197,7 @@ class ClienteModel extends \App\Models\BaseModel "fecha_vencimiento" => [ "max_length" => "Clientes.validation.fecha_vencimiento.max_length", ], - "is_deleted" => [ - "integer" => "Clientes.validation.is_deleted.integer", - "required" => "Clientes.validation.is_deleted.required", - ], + "limite_credito" => [ "decimal" => "Clientes.validation.limite_credito.decimal", "required" => "Clientes.validation.limite_credito.required", @@ -287,7 +284,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id" ) - ->where("is_deleted", 0);; + ->where("t1.deleted_at", null);; $builder->join("users t5", "t1.comercial_id = t5.id", "left"); $builder->join("formas_pago t7", "t1.forma_pago_id = t7.id", "left"); @@ -315,7 +312,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.limite_credito AS limite_credito" ) - ->where("t1.is_deleted", 0) + ->where("t1.deleted_at", null) ->where("t1.id", $cliente_id); $limite = $builder->get()->getResultObject(); @@ -340,7 +337,7 @@ class ClienteModel extends \App\Models\BaseModel t2.nombre AS cliente_pais, t1.cp AS cliente_cp, t1.ciudad AS cliente_ciudad, t3.nombre AS cliente_provincia, t1.credito_asegurado AS creditoAsegurado" ) - ->where("t1.is_deleted", 0) + ->where("t1.deleted_at", null) ->where("t1.id", $cliente_id); $builder->join("lg_paises t2", "t1.pais_id = t2.id", "left"); $builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left"); @@ -394,7 +391,7 @@ class ClienteModel extends \App\Models\BaseModel "t1.nombre AS nombre" ) ->where("id", $id) - ->where("is_deleted", 0); + ->where("t1.deleted_at", null); return $builder->get()->getResultObject()[0]->nombre; } catch (\Exception $e) { @@ -409,7 +406,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.id AS id, t1.nombre AS name" ) - ->where("is_deleted", 0); + ->where("t1.deleted_at", null); return empty($search) ? $builder->get()->getResultObject() : $builder @@ -586,7 +583,7 @@ class ClienteModel extends \App\Models\BaseModel $result['limite_credito'] = $this->db->table('clientes') ->select('limite_credito') ->where('id', $cliente_id) - ->where('is_deleted', 0) + ->where("deleted_at", null) ->get() ->getResultObject()[0]->limite_credito; $result['limite_credito'] = round(floatval($result['limite_credito']), 2); diff --git a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php index 8b6562e3..c15bbad2 100755 --- a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php +++ b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php @@ -36,7 +36,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel "tiempo_max", "precio_hora", "margen", - "is_deleted", "deleted_at", "created_at", "updated_at", @@ -45,11 +44,12 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosLineasEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; protected $createdField = "created_at"; protected $updatedField = "updated_at"; + protected $deletedField = 'deleted_at'; public static $labelField = "plantilla_id"; @@ -121,7 +121,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $this->db ->table($this->table . " t1") ->where('t1.plantilla_id', $plantilla_id) - ->set('is_deleted', 1) ->set('deleted_at', $date_value) ->update(); @@ -152,7 +151,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $builder->join("users t2", "t1.user_updated_id = t2.id", "left"); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', 0); $builder->where('t1.plantilla_id', $plantilla_id); if (empty($search)) @@ -181,7 +180,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $rows = $this->db ->table($this->table) ->select("id, tiempo_min, tiempo_max") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("tipo", $data["tipo"]) ->where("tipo_maquina", $data["tipo_maquina"]) ->where("tipo_impresion", $data["tipo_impresion"]) diff --git a/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php b/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php index c3f55da2..4b30e15f 100755 --- a/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php @@ -19,11 +19,12 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel protected $useAutoIncrement = true; - protected $allowedFields = ["nombre", "is_deleted", "deleted_at", "created_at", "updated_at"]; + protected $allowedFields = ["nombre", "deleted_at", "created_at", "updated_at"]; protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; @@ -61,7 +62,7 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel "t1.id as id, t1.nombre AS nombre" ); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', null); if (empty($search)) return $builder; diff --git a/ci4/app/Models/Clientes/ClientePreciosModel.php b/ci4/app/Models/Clientes/ClientePreciosModel.php index dd749161..17693fd2 100755 --- a/ci4/app/Models/Clientes/ClientePreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePreciosModel.php @@ -34,7 +34,6 @@ class ClientePreciosModel extends \App\Models\BaseModel "tiempo_max", "precio_hora", "margen", - "is_deleted", "deleted_at", "created_at", "updated_at", @@ -45,7 +44,8 @@ class ClientePreciosModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClientePreciosEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; @@ -140,7 +140,6 @@ class ClientePreciosModel extends \App\Models\BaseModel $this->db ->table($this->table . " t1") ->where('cliente_id', $cliente_id) - ->set('is_deleted', 1) ->set('deleted_at', $date_value) ->set('user_updated_id', $session->id_user) ->update(); @@ -153,7 +152,7 @@ class ClientePreciosModel extends \App\Models\BaseModel // Se borran los valores existentes para todos los clientes en una sola consulta $modelCliente = model('App\Models\Clientes\ClienteModel'); - $clientes = $modelCliente->select('id')->where('is_deleted', 0)->findAll(); + $clientes = $modelCliente->select('id')->where('deleted_at', null)->findAll(); // Se borra la tabla $this->db->table($this->table)->truncate(); @@ -288,7 +287,7 @@ class ClientePreciosModel extends \App\Models\BaseModel ->table($this->table . " t1") ->select("t1.cliente_id AS id") ->where('t1.plantilla_id', $plantilla_id) - ->where('t1.is_deleted', 0) + ->where('t1.deleted_at', null) ->distinct() ->get()->getResultArray(); // Extraer solo los IDs de los clientes @@ -359,7 +358,7 @@ class ClientePreciosModel extends \App\Models\BaseModel ->where('tipo_impresion', $config->tipo_impresion) ->where('tiempo_min <=', $tiempo) ->where('tiempo_max >=', $tiempo) - ->where('is_deleted', 0) + ->where('deleted_at', null) ->get()->getResultObject(); if (count($values) > 0) { @@ -389,7 +388,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $builder->join("users t2", "t1.user_updated_id = t2.id", "left"); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', 0); $builder->where('t1.cliente_id', $cliente_id); if (empty($search)) @@ -415,7 +414,7 @@ class ClientePreciosModel extends \App\Models\BaseModel "t1.plantilla_id AS id, t2.nombre AS nombre" ); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', null); $builder->where('t1.cliente_id', $cliente_id); $builder->join("cliente_plantilla_precios t2", "t1.plantilla_id = t2.id", "left"); $builder->limit(1); @@ -442,7 +441,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $rows = $this->db ->table($this->table) ->select("id, tiempo_min, tiempo_max") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("tipo", $data["tipo"]) ->where("tipo_maquina", $data["tipo_maquina"]) ->where("tipo_impresion", $data["tipo_impresion"]) @@ -476,7 +475,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $value = $this->db ->table($this->table) ->select("plantilla_id") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("cliente_id", $cliente_id) ->limit(1)->get()->getResultObject(); diff --git a/ci4/app/Models/Clientes/ClienteUsuariosModel.php b/ci4/app/Models/Clientes/ClienteUsuariosModel.php index e735d7d2..c1b5ade5 100644 --- a/ci4/app/Models/Clientes/ClienteUsuariosModel.php +++ b/ci4/app/Models/Clientes/ClienteUsuariosModel.php @@ -26,7 +26,8 @@ class ClienteUsuariosModel extends ShieldUserModel protected $returnType = "App\Entities\Usuarios\UserEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 6a237646..317bd12d 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -787,10 +787,7 @@ $(document).on('click', '.btn-remove', function(e) { },{ "name": "deleted_at", "type": "hidden" - },{ - "name": "is_deleted", - "type": "hidden" - }, + } ] } );